通过jQuery Ajax发送Json数组 [英] Send Json Array Through jQuery Ajax
本文介绍了通过jQuery Ajax发送Json数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将通过jquery ajax调用将json对象数组发送到php文件.
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);
如何通过jquery ajax发送数组?以及如何获取php中的值? 谢谢.
How can I send the array through jquery ajax? and how can I get the values in php? Thanks.
推荐答案
$.ajax({
url: "api",
type: "POST",
dataType: 'json',
data: JSON.stringify(arr),
success: function(response){}
});
使用PHP:
$strRequest = file_get_contents('php://input');
$Request = json_decode($strRequest);
这篇关于通过jQuery Ajax发送Json数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文