在前端新建了一个数组
var arr = new Array();
arr.push("{product:" + "p1" + "}");
arr.push("{product:" + "p2" + "}");
然后向php发送了一个ajax请求,
$.ajax({
url: "model=index&controller=index&action=save",
data: {arr: arr},
dataType: "json",
type: "get",
success: function(json) {
if (json.success) {
alert("succ");
} else {
alert("false");
}
},
error: function() {
alert("error");
}
})
在ajax发送以前,
alert(arr); 结果为{product:p1},{product:p2} 没有方括号
console.info(arr);在控制台看到的是[{product:p1},{product:p2}]
问题一:为什么alert不带方括号
在php端接收以后
$arr= $_GET["arr"];
问题二:为什么$arr也是不带方括号的
最好能从原理上解释一下,谢谢各位老板