problem with sending array with jquery ajax
var myNames= ["Chris","Kate","Steve"];
$.ajax
({
cache:false,
type: "POST",
url: "check.php?timestamp="+new Date().getTime(),
data: "myCars[]=开发者_运维技巧"+myCars,
success: function(msg)
{
...
}
});
with var_dump($myNames)
in php page i see
array(1) { [0]=> string(16) "Chris,Kate,Steve" }
but i expect
array(3) {....}
why i see array(1) { [0]=> string(16) "Chris,Kate,Steve" }
There's a better way of doing this - just pass an object for data
:
var myNames= ["Chris","Kate","Steve"];
$.ajax
({
cache:false,
type: "POST",
url: "check.php?timestamp="+new Date().getTime(),
data: {'myNames': myNames},
success: function(msg)
{
...
}
});
jQuery will encode it for you.
精彩评论