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;
});
精彩评论