You can just pass a javascript object.
JS:
var array = [1,2,3];
$.ajax({
type: "POST",
url: "parse_array.php",
data: {"myarray": array, 'anotherarray': array2},
dataType: "json",
success: function(data) {
alert(data.reply);
}
});
On the php side, you need to print the JSON code:
PHP:
$array = $_POST['myarray'];
print '{"reply": 1}';
source
share