[英]Send jQuery $.data object through $.ajax GET
I have a form with a pile of input fields. 我有一个带有一堆输入字段的表单。 I want to make a ajax GET request with all of the fields!
我想用所有字段做一个ajax GET请求! 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泵送它:
$.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. 但当然它不起作用...没有$ _GET变量显示在otherpage.php中,并且控制台显示
myData
是一个巨大的对象交易。
How do you send data through ajax like this? 你如何通过像这样的Ajax发送数据? Is there a better way?
有没有更好的办法?
Use the jQuery serialize();
使用jQuery
serialize();
method: 方法:
$.ajax({
type:"GET",
url: '/otherpage.php',
data = $('#myForm').serialize(),
error(function(){}),
success(function(){});
});
http://api.jquery.com/serialize/ http://api.jquery.com/serialize/
$.ajax({
type:"GET",
url: '/otherpage.php',
data = $('#myForm').serialize(),
error(function(){}),
success(function(){});
});
Hope it'will help you. 希望它能帮到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.