[英]How can I make an prototype ajax request with an array of values as a parameter?
i'm trying to make a ajax update in prototype with some values from a multirecordselect that sends a requests like. 我试图用发送请求之类的multirecordselect中的一些值在原型中进行ajax更新。
Parameters: {"action"=>"use_campaign", "campaigns"=> ["27929","27932"] , "advertiser_id"=>"", "controller"=>"admin/reporting", "ad_id"=>""}
as you can see the request sends the "campaigns" elements as an array of values, i'm trying to do the same with this js code over prototype 7. 如您所见,请求将“广告系列”元素作为值数组发送,我正在尝试在原型7上使用此js代码执行相同的操作。
// get the campaigns
var campaign_ids = {};
var campaigns = $('filter_form').getInputs("hidden","report[campaigns][]");
campaigns.each( function(field) {
campaign_ids.push(field.value);
});
new Ajax.Updater('ad_filter', '/admin/reporting/use_campaign', {
method : 'get',
asynchronous : true,
evalScripts : true,
parameters : {
'advertiser_id' : $('filter_form')['report[advertiser_id]'].value,
'ad_id' : $('filter_form')['report[ad_id]'].value,
'campaigns' : campaign_ids
}
});
the campaigns_ids is getting the correct info as an array like: campaigns_ids正在获取正确的信息,例如数组:
[ "27929", "27932" ]
but seems that prototype ajax update is sending a request like: 但似乎原型ajax更新正在发送如下请求:
http://my_domain/admin/reporting/use_campaign?ad_id=&advertiser_id=&campaigns=27929&campaigns=27932
what sends parameters like: 发送参数的内容如下:
Parameters: {"action"=>"use_campaign", "campaigns"=> "27929" , "advertiser_id"=>"", "controller"=>"admin/reporting", "ad_id"=>""}
I also tryed with 我也尝试过
Object.toJSON(campaign_ids)
but i only get an escaped string like 但是我只得到一个转义的字符串
Parameters: {"action"=>"use_campaign", "campaigns"=>"[\"27929\",\"27932\"]" , "advertiser_id"=>"", "controller"=>"admin/reporting", "ad_id"=>""}
There is anyway to do this as I wish? 无论如何,我愿意这样做吗?
Thanks for all. 谢谢大家
It looks like you use PHP as a back-end framework. 看起来您使用PHP作为后端框架。 To make sure PHP understands array-like GET parameters, you need to add a
[]
to the parameter name: 为了确保PHP能够理解类似数组的GET参数,您需要在参数名称中添加
[]
:
parameters : {
//...
'campaigns[]' : campaign_ids
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.