通过jQuery Ajax发送Json数组

Cha*_*Dou 4 php jquery json getjson

我将通过jquery ajax调用发送一个json对象数组到一个php文件.

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);
Run Code Online (Sandbox Code Playgroud)

如何通过jquery ajax发送数组?我怎样才能在php中获取值?谢谢.

Fel*_*orf 14

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

       });
Run Code Online (Sandbox Code Playgroud)

并使用PHP:

$strRequest = file_get_contents('php://input');
$Request = json_decode($strRequest);
Run Code Online (Sandbox Code Playgroud)