开发者

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜