通过$.ajaxGET发送jQuery$.data对象


Send jQuery $.data object through $.ajax GET

我有一个带有一堆输入字段的表单。我想对所有字段发出ajax GET请求!到目前为止,最简单的方法似乎是将输入分配给数据对象:

$('#myForm').find('input').each(function(index){ 
    myData = $.data($('#myForm'), $(this).attr('name'), $j(this).val());
});

然后通过ajax将其泵送:

$.ajax({
    type:"GET",
    url: '/otherpage.php',
    data = myData,
    error(function(){}),
    success(function(){});
});

但它当然不起作用。。。otherpage.php中没有显示$_GET变量,控制台显示myData是一个巨大的对象。

如何像这样通过ajax发送数据?有更好的方法吗?

使用jQuery serialize();方法:

$.ajax({
    type:"GET",
    url: '/otherpage.php',
    data = $('#myForm').serialize(),
    error(function(){}),
    success(function(){});
});

http://api.jquery.com/serialize/

$.ajax({
    type:"GET",
    url: '/otherpage.php',
    data = $('#myForm').serialize(),
    error(function(){}),
    success(function(){});
});

希望对你有帮助。