我正在尝试以 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],... 。
最佳答案
尝试以下伪代码:
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
})
});
关于javascript - 如何在$.params中动态传递参数数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46388222/