开发者

How to post a array with $.post?

Here is my array:

开发者_JAVA百科
arr[0]='A';
arr[1]='B';
....

I tried to post it this way:

$.post('data.php',arr,function() {

});

But fails to work as expected.


From the manual:

data (Optional) Map, String

Key/value pairs or the return value of the .serialize() function that will be sent to the server.

And from the examples in the manual:

$.post("test.php", { 'choices[]': ["Jon", "Susan"] });

Therefore:

$.post("test.php", { 'arr[]': arr });


You can't post an array. What you need is a hash:

parameters = { "Param1" : "A", "Param2" : "B" };

Choose a suitable name and convert your array to a hash:

hash = {};
$.each(arr, function(i, elem) {
 hash["Param" + i] = elem;
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜