2017-09-24 29 views
0

我想在X WWW的形式formurlencoded發送此輸入參數:

customer_id, 
xyz, 
order_total, 
order_location, 
item_id[0] 
item_quantity[0], 
res_id, 
item_id[1], 
item_quantity[1] 

現在,如下圖所示我的網絡請求代碼:

return $http({ 
       method: "POST", 
       headers: { 
        'Content-Type': 'application/x-www-form-urlencoded', 
        'Authorization': 'Bearer ' + user_token 
       }, 
       url: config.server_url + "orders", 
       data: $.param({ 
        'customer_id': user_id, 
        'xyz': '', 
        'order_total': '50.09', 
        'order_location': 'abc', 
        'res_id': res_id, 
        'item_id[0]':'dkkdskds', 
        'item_quanitity[0]':1, 
        'item_id[1]':'dkkdskds', 
        'item_quanitity[1]':1, 
        'item_id[2]':'dkkdskds', 
        'item_quanitity[2]':1, 
       }) 
      }); 

現在,我不知道如何動態地傳遞item_id [0],item_id [1],item_id [2],...。

+1

嘗試這種'變種ARR = [33,55,77]; ... $ .PARAM({ ... \t \t \t 'ITEM_ID':改編 })' – vnt

回答

1

嘗試使用以下僞代碼:

var array1 = ['dkkdskds' , 'dkkdskds2', 'dkkdskds3'] ; 
var array2 = [1 , 2, 3] ; 

return $http({ 
    method: "POST", 
    headers: { 
      'Content-Type': 'application/x-www-form-urlencoded', 
      'Authorization': 'Bearer ' + user_token 
     }, 
      url: config.server_url + "orders", 
      data: $.param({ 
        'customer_id': user_id, 
        'xyz': '', 
        'order_total': '50.09', 
        'order_location': 'abc', 
        'res_id': res_id, 
        'item_id': array1, 
        'item_quanitity': array2 
       }) 
      });