2012-03-28 39 views
1

我試圖做一個ajax更新原型與一些multirecordselect值發送請求。如何使用值數組作爲參數進行原型ajax請求?

Parameters: {"action"=>"use_campaign", "campaigns"=> ["27929","27932"] , "advertiser_id"=>"", "controller"=>"admin/reporting", "ad_id"=>""} 

,你可以看到該請求發送「運動」元素值的數組,我試圖做同樣的這個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 
       } 
}); 

的campaigns_ids在得到正確的信息像數組:

[ "27929", "27932" ] 

但目前看來,原型阿賈克斯更新發送請求等:

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"=>""} 

我也tryed與

Object.toJSON(campaign_ids) 

但我只得到一個轉義字符串像

Parameters: {"action"=>"use_campaign", "campaigns"=>"[\"27929\",\"27932\"]" , "advertiser_id"=>"", "controller"=>"admin/reporting", "ad_id"=>""} 

有無論如何要做到這一點作爲我希望?

謝謝大家。

+0

OK愚蠢的我,只是把正確的參數「活動[]」而不是「運動」。對不起,請求=) – andresbravog 2012-03-28 11:23:10

回答

5

它看起來像你使用PHP作爲後端框架。 爲了確保PHP懂得陣列狀的GET參數,你need to add一個[]參數名:

  parameters : { 
       //... 
       'campaigns[]' : campaign_ids 
      } 
+0

謝謝我解決了它,併發布了一個評論,因爲stackoverflow dosen't讓我回答自己...無論如何thak。我用鋼軌=) – andresbravog 2012-03-28 11:35:47

+0

啊,有趣。看起來RoR遭受同樣的問題。 – user123444555621 2012-03-28 11:45:01

相關問題