提交的数组通过JQuery的AJAX的关键 [英] Submitting an array with a key via JQuery ajax
问题描述
即时通讯提交的值通过jQuery AJAX的数组,但我的servlet只有拿起数组中的第一个值,当它有更多的元素。
im submitting an array of values via jquery ajax, but my servlet only picks up the first value in the array, when it has many more elements.
$.ajax({
type: "POST",
url: "myServlet",
data: ({'item':itemsArr})
});
数组看起来像: VAR lovelyArray = [蛋糕,丁字裤,supermanDoll];
出来一样的另一面:&放大器;项目=蛋糕
..和多数民众赞成它
comes out the other side like: &item=cake
.. and thats it.
我期待它出来像项目=饼放;项目=丁字裤和放大器;项目= supermanDoll
任何帮助是非常AP preciated在这个问题上。
Any help is much appreciated on this matter.
感谢。
推荐答案
您可以使用 <$ C $ 。C> $参数 序列化阵列,像这样的:
You can use $.param
to serialize your array, like this:
$.ajax({
type: "POST",
url: "myServlet",
data: $.param({'item': itemsArr}) // item[]=cake&item[]=thong&item[]=supermanDoll
});
以上输出假设你正在使用jQuery 1.4+。如果你正在使用jQuery 1.3.2或更早的版本,输出如下:
The above output assumes that you are using jQuery 1.4+. If you are using jQuery 1.3.2 or earlier, the output will look like:
item=cake&item=thong&item=supermanDoll
这篇关于提交的数组通过JQuery的AJAX的关键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!