我正在尝试使用来自发送请求的多记录选择中的一些值在原型中进行ajax更新。
Parameters: {"action"=>"use_campaign", "campaigns"=> ["27929","27932"] , "advertiser_id"=>"", "controller"=>"admin/reporting", "ad_id"=>""}
正如您所看到的,请求将“campaigns”元素作为值数组发送,我正在尝试使用此js代码对原型7执行相同的操作。
// 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
}
});
campaign_ids正在获取正确的信息,如:
[ "27929", "27932" ]
但似乎原型ajax更新发送的请求如下:
http://my_domain/admin/reporting/use_campaign?ad_id=&advertiser_id=&campaigns=27929&campaigns=27932
发送的参数如下:
Parameters: {"action"=>"use_campaign", "campaigns"=> "27929" , "advertiser_id"=>"", "controller"=>"admin/reporting", "ad_id"=>""}
我也试过
Object.toJSON(campaign_ids)
但我只获得了像
这样的转义字符串Parameters: {"action"=>"use_campaign", "campaigns"=>"[\"27929\",\"27932\"]" , "advertiser_id"=>"", "controller"=>"admin/reporting", "ad_id"=>""}
无论如何,我希望这样做吗?
谢谢大家。
答案 0 :(得分:7)
看起来您使用PHP作为后端框架。
为了确保PHP理解类似数组的GET参数,您need to add []
参数名称:
parameters : {
//...
'campaigns[]' : campaign_ids
}