Reputation: 838
I've got an array like this one :
var cars = new Array();
cars['mom'] = "Ford";
cars['dad'] = "Honda";
I want to send the array cars via jQuery .ajax() function :
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);
}
});
How can I read the array on the server side, with my PHP script ?
Thanks !
Upvotes: 0
Views: 777
Reputation: 31033
$.ajax({
url: path+'/inc/ajax/cars.php',
data: {cars:$(cars).serializeArray()},
cache: false,
type: "POST",
success : function(text){
alert(text);
}
});
php
$arr = $_POST['cars'];
Upvotes: 0