javascript - Send jQuery $.data object through $.ajax GET - Stack Overflow

I have a form with a pile of input fields. I want to make a ajax GET request with all of the fields! Ea

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 badges
Add a ment  | 

2 Answers 2

Reset to default 6

Use 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

相关推荐

  • javascript - Send jQuery $.data object through $.ajax GET - Stack Overflow

    I have a form with a pile of input fields. I want to make a ajax GET request with all of the fields! Ea

    8小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信