I have a form with a pile of input fields. I want to make a ajax GET request with all of the fields! Easiest way so far looks like assigning the inputs to a data object:
$('#myForm').find('input').each(function(index){
myData = $.data($('#myForm'), $(this).attr('name'), $j(this).val());
});
...and then pump it through the ajax:
$.ajax({
type:"GET",
url: '/otherpage.php',
data = myData,
error(function(){}),
success(function(){});
});
But of course it doesn't work... no $_GET variables show up in the otherpage.php, and the console shows that myData
is some huge object deal.
How do you send data through ajax like this? Is there a better way?
I have a form with a pile of input fields. I want to make a ajax GET request with all of the fields! Easiest way so far looks like assigning the inputs to a data object:
$('#myForm').find('input').each(function(index){
myData = $.data($('#myForm'), $(this).attr('name'), $j(this).val());
});
...and then pump it through the ajax:
$.ajax({
type:"GET",
url: '/otherpage.php',
data = myData,
error(function(){}),
success(function(){});
});
But of course it doesn't work... no $_GET variables show up in the otherpage.php, and the console shows that myData
is some huge object deal.
How do you send data through ajax like this? Is there a better way?
Share Improve this question edited Dec 22, 2015 at 11:15 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jan 21, 2012 at 21:02 emcemc 5071 gold badge7 silver badges25 bronze badges2 Answers
Reset to default 6Use the jQuery serialize();
method:
$.ajax({
type:"GET",
url: '/otherpage.php',
data = $('#myForm').serialize(),
error(function(){}),
success(function(){});
});
http://api.jquery./serialize/
$.ajax({
type:"GET",
url: '/otherpage.php',
data = $('#myForm').serialize(),
error(function(){}),
success(function(){});
});
Hope it'will help you.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745172236a4614997.html
评论列表(0条)