我有一个带有一堆输入字段的表单。我想对所有字段发出 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(){});
});
但是当然它不起作用...没有 $_GET 变量出现在 otherpage.php 中,并且控制台显示 myData
是一些巨大的对象交易。
如何通过ajax发送数据?有没有更好的办法?
最佳答案
使用 jQuery serialize();
方法:
$.ajax({
type:"GET",
url: '/otherpage.php',
data = $('#myForm').serialize(),
error(function(){}),
success(function(){});
});
关于javascript - 通过 $.ajax GET 发送 jQuery $.data 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8956641/