I am trying to get the records from JSON file,
the results showing only the first data..could you please help how can I show all the records in table a tr
$.ajax({
url: 'records.json'
}).done(function(data){
$('#content1').text(data[0].id);
$('#content2').text(data[0].date);
$('#content3').text(data[0].description);
$('#content4').text(data[0].amount);
});
Related
I wanted post a form on click of row of table and pass that row data with it. I am passing data to controller using ajax.
$("#return_table tr").click(function(e){
$(this).addClass('selected').siblings().removeClass('selected');
var name = $("#cityName").val();
var initial = $("#cityInitial").val();
$.ajax({
headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
type:'post',
data: $('#return_flight').serialize(),
success: function () {
alert('form was submitted');
}
});
});
This is my ajax.
My route is Route::post('/dashboard/return','Users\BookTicketController#retrunTime');
When I click on any row then I am getting error that POST http://127.0.0.1/dashboard/return 500 (Internal Server Error)
What is a issue with this code?
The issue is not in this code It probably occurring at your backend code, check your retrunTime function implementation.
check out this link understand more about why and when 500 error occurs.
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500
I am trying to ajax a form to a different domain using the jquery.xdomainajax.js plugin and having issue getting the desired HTML back (follow up to this question: Display form result in same page with only client-side script possible?)
The destination script checks the user id against the membership database, and redirects to an error page if the user has already submitted the form, or redirect to a thank you page if the entry is valid.
Using the script below, I get back the HTML of the ORIGINAL page on which the form is displayed, not the error page or the thank you page. If I change the dataType from "text" or "html" to "jsonp", I get a parse error as expected, but the associated HTML is actually desired HTML. I am not quite sure why.
Any help would be much appreciated!
PS: I do not have control over anything in the remote server.
$.ajax({
type: settings.postType, //GET
url: settings.tourl,
data: aForm.serialize(),
dataType: settings.type, //text or HTML
crossDomain: true,
success: function(data, textStatus, jqXHR){
alert(data.responseText);
settings.success(data);
},
error: function (jqXHR, textStatus, errorThrown){
//alert(errorThrown);
console.log(textStatus);
settings.error();
}
});
Should your request type be a POST instead of a GET? Generally form info will be sent with a POST.
I used this code from
Change table cell from span to input on click-
The replace one for inline edit now i want to post values through ajax and i am not sure how.
I just want to post the comments the users have edited and update them on the database
This is how i got so far:
$.ajax({
type: "POST",
url: "comments.php",//to update the comments
data: "data"
});
Not sure what to put next. Is it possible to post values when user click out of input area? and does the data have to be serialize?
Thanks in advance!
$.ajax({
type: "POST",
url: "comments.php",//to update the comments
data: {"comments":$("yourformId").serialize()},
success:function(res)
{
//Do what ever you want
}
});
And in your comments.php just print_r($_POST) will give you the posted array via ajax
If you use form.serialize you will get all the data from the form you submitted
I have an index as an extra searching option for my jqGrid:
<a class="letter" href="javascript:void">C</a>
$(".letter").click(
function (e) {
e.preventDefault();
var letter = this.innerHTML;
$.ajax({
url: '#Url.Action("Products")',
type:'POST',
data: '_search=true&nd=1345531875941&rows=5&page=1&sidx=ProductID&sord=asc&filters=%7B%22groupOp%22%3A%22AND%22%2C%22rules%22%3A%5B%7B%22field%22%3A%22ProductName%22%2C%22op%22%3A%22bw%22%2C%22data%22%3A%22'+letter+ '%22%7D%5D%7D&searchField=&searchString=&searchOper=',
success: function(data){
jQuery("#jqgProducts")[0].addJSONData(data);
}
});
});
The data retrieved is fine (rows starting with 'C'), the pager shows : 'page 1 of 2'. However when I want to go to the second page it does not display the right data( Which would be the other Names that start with 'C'). How can I make the page display the right data?
data: '_search=true&nd=1345531875941&rows=5&page=1&sidx=ProductID&sord=asc&filters=%7B%22groupOp%22%3A%22AND%22%2C%22rules%22%3A%5B%7B%22field%22%3A%22ProductName%22%2C%22op%22%3A%22bw%22%2C%22data%22%3A%22'+letter+ '%22%7D%5D%7D&searchField=&searchString=&searchOper='
dynamically pass the parameter test "page=1" to "page=2" or manually for testing purposes
Manually:
data: '_search=true&nd=1345531875941&rows=5&page=2&sidx=ProductID&sord=asc&filters=%7B%22groupOp%22%3A%22AND%22%2C%22rules%22%3A%5B%7B%22field%22%3A%22ProductName%22%2C%22op%22%3A%22bw%22%2C%22data%22%3A%22'+letter+ '%22%7D%5D%7D&searchField=&searchString=&searchOper='
Dynamically:
data: '_search=true&nd=1345531875941&rows=5&page='+anyPage+'&sidx=ProductID&sord=asc&filters=%7B%22groupOp%22%3A%22AND%22%2C%22rules%22%3A%5B%7B%22field%22%3A%22ProductName%22%2C%22op%22%3A%22bw%22%2C%22data%22%3A%22'+letter+ '%22%7D%5D%7D&searchField=&searchString=&searchOper='
In one of my Active Admin index pages, I list some records in a table.
I've added the jQuery sortable plugin to be able to sort the records by dragging the items vertically. This works fine, and the position attribute for every records updates correctly (via ajax).
Though, if I refresh Active Admin after the ajax call, I get signed out and have to login again.
Ajax sends this data:
faq[]=1&faq[]=3&faq[]=2
The sort method:
def sort
params[:faq].each_with_index do |id, index|
Faq.update_all({position: index+1}, {id: id})
end
render nothing: true
end
The ajax response is empty and doesn't give any exception.
Why I am signed out?
I had to add the X-CSRF-Token to the ajax headers for some reason. I'm not sure why. Shouldn't rails.js do that for me?
Working solution:
$.ajax({
url: "/faqs/sort",
type: "post",
beforeSend: function(xhr) {
xhr.setRequestHeader('X-CSRF-Token', $('meta[name="csrf-token"]').attr('content'));
},
data: $(this).sortable('serialize')
});