Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send Json Array Through jQuery Ajax

I am going to send a array of json object through jquery ajax call to a php file.

var arr = new Array();
var record1 = {'a':'1','b':'2','c':'3'};
var record2 = {'d':'4','e':'5','f':'6'};
arr.push(record1);
arr.push(record2);

How can I send the array through jquery ajax? and how can I get the values in php? Thanks.

like image 324
CharlesDou Avatar asked Nov 30 '22 22:11

CharlesDou


1 Answers

$.ajax({
        url: "api",
        type: "POST",
        dataType: 'json',
        data: JSON.stringify(arr),
        success: function(response){}

       });

And with PHP:

$strRequest = file_get_contents('php://input');
$Request = json_decode($strRequest);
like image 67
Felix Wessendorf Avatar answered Dec 04 '22 04:12

Felix Wessendorf