Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过$.ajax GET发送jQuery$.data对象_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript 通过$.ajax GET发送jQuery$.data对象

Javascript 通过$.ajax GET发送jQuery$.data对象,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我有一个表单,有一堆输入字段。我想对所有字段发出一个ajax GET请求!迄今为止最简单的方法是将输入分配给数据对象: $('#myForm').find('input').each(function(index){ myData = $.data($('#myForm'), $(this).attr('name'), $j(this).val()); }); …然后通过ajax泵送: $.ajax({ type:"GET", url: '/otherpage.php

我有一个表单,有一堆输入字段。我想对所有字段发出一个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中没有显示$\u GET变量,控制台显示
myData
是一个巨大的对象处理


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

使用jQuery
serialize()方法:

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


希望它能帮助你。

就这么简单,是吗?真不敢相信我没有发现。。。谢谢男人:)没问题,很高兴它有帮助!将答案标记为已接受,以便其他人在遇到相同问题时可以找到解决方案:)
$.ajax({
    type:"GET",
    url: '/otherpage.php',
    data = $('#myForm').serialize(),
    error(function(){}),
    success(function(){});
});