我有一个像这样的数组:
var cars = new Array();
cars['mom'] = "Ford";
cars['dad'] = "Honda";
我想通过jQuery .ajax()函数发送数组汽车:
var oDate = new Date();
$.ajaxSetup({
cache: false
});
$.ajaxSetup({ scriptCharset: "utf-8" ,contentType: "application/x-www-form-urlencoded; charset=UTF-8" });
$.ajax({
url: path+'/inc/ajax/cars.php',
data: {cars:cars},
cache: false,
type: "POST",
success : function(text){
alert(text);
}
});
如何使用我的PHP脚本在服务器端读取数组?
谢谢!
答案 0 :(得分:1)
尝试使用php特殊数组$_POST
答案 1 :(得分:0)
$php_array = json_decode($_POST['cars']);
答案 2 :(得分:0)
$.ajax({
url: path+'/inc/ajax/cars.php',
data: {cars:$(cars).serializeArray()},
cache: false,
type: "POST",
success : function(text){
alert(text);
}
});
PHP
$arr = $_POST['cars'];