0

I Have a simple array which looks like

var arr = ["foo", "2015/11/04", "Jill", "Smith", "60"]
var serializedArr = JSON.stringify( arr );

now can you please let me know how I can load the serializedArr into the data in following ajax request?

var upload = $.ajax({
    type: "POST",
    url: "assets/.../loader.php",
    data: data,
    cache: false,
    beforeSend: function() {
    }
});

and also how to read the data on server side PHP file? Thanks

Behseini
  • 6,066
  • 23
  • 78
  • 125
  • 1
    Possible duplicate of [Passing JavaScript Array To PHP Through JQuery $.ajax](http://stackoverflow.com/questions/2013728/passing-javascript-array-to-php-through-jquery-ajax) – Narendrasingh Sisodia Nov 05 '15 at 06:13

1 Answers1

1
var upload = $.ajax({
    type: "POST",
    url: "assets/.../loader.php",
    data: {array:serializedArr},// pass here{key:value,key:value,...}
    cache: false,
    beforeSend: function() {
    }
});

In php

$array = json_decode($_POST['array']);
print_r($array);// this will get back the array which was encoded.

You have to decode the array because, array is encoded(JSON.stringify(arr))

Niranjan N Raju
  • 12,047
  • 4
  • 22
  • 41