如何在ajax post上将对象数组作为参数传递 [英] how to pass array of objects as parameters on ajax post
本文介绍了如何在ajax post上将对象数组作为参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下数组对象
[{"site":"88333","event":"TEST","event_window":"4th April - 4th April","monitoring_start":"10-Apr-2016","monitoring_end":"10-Apr-2016"}]
我正在尝试将ajax发布作为键值.我可以有多行.我已经尝试了$.param(JSON.stringify(json_o))
和$.param(json_o)
,它们不起作用
I am trying to pass on ajax post as key value. I can have multiple rows. I have tried $.param(JSON.stringify(json_o))
and $.param(json_o)
, which does not work
显示的示例此处看起来像我已经完成但不起作用的数组对象. /p>
Example shown here looks like array object which I have done but does not work.
var params = JSON.stringify(json_o);
console.log(params);
$.ajax({
url : '../../api/netcool/add-event',
data : params,
type: 'POST',
error : function (data, textStatus, jqXHR) {
if(data.statusText != "abort")
console.log(data);
},
dataType : 'json',
success : function (data) {
console.log(data);
}
});
推荐答案
尝试一下..
var params = [{"site":"88333","event":"TEST","event_window":"4th April - 4th April","monitoring_start":"10-Apr-2016","monitoring_end":"10-Apr-2016"}];
console.log(params);
$.ajax({
url : '../../api/netcool/add-event',
data : {params:params},
type: 'POST',
error : function (data, textStatus, jqXHR) {
if(data.statusText != "abort")
console.log(data);
},
success : function (data) {
console.log(data);
}
});
在../../api/netcool/add-event方法中,您可以通过
And in ../../api/netcool/add-event method.. you can acccess the parameter by
print_r($_REQUEST['params'][0]);
echo $_REQUEST['params'][0]['site'];
这篇关于如何在ajax post上将对象数组作为参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文