在jQuery ajax中传递数组 [英] Pass array in jQuery ajax
本文介绍了在jQuery ajax中传递数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的幻想代码:
$(document).ready(function() {
$("#sub").click(function() {
info['moto'] = $("#moto").val();
info['motox'] = $("#motox").val();
$.ajax({
type: "POST",
url: "index.php",
data: "arr="+info,
success: function(msg){
$('.answer').html(msg);
}
})
})
})
我怎样才能使它在.php文件中接收后,可以使用POST方法:$_POST['moto']
和$_POST['motox']
或类似的方法?我应该改变什么?谢谢.
How could I make, that after receiving it in .php file I could use POST method like this: $_POST['moto']
and $_POST['motox']
or something like that? What should I change? Thanks.
推荐答案
刚刚:
data: info,
(首先,您需要将info初始化为对象:var info = {}
)
(And you need to initialize info as an object in the first place: var info = {}
)
这篇关于在jQuery ajax中传递数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文