如何使用AngularJS $ http.delete
发送数组类型参数// notificationIds is array of ids.
deleteNotification(notificationIds) {
let query = `/notifications`
let params = {}
notificationIds.forEach((id, index) => {
params[`notificationIds[${index}]`] = id
})
return $http.delete(`wis`, query, params)
.then((response) => response)
}
==>但结果是:(错误请求!!)
请求方法:DELETE
状态代码:400错误请求
答案 0 :(得分:0)
我要感谢你们:)。这是正确的答案
deleteNotification(notificationIds) {
let query = `/notifications`
let data = ''
notificationIds.forEach((id, index) => {
data.length > 0 ? data += '&' : data += ''
data += `notificationIds[${index}]=${id}`
})
const config = {
data: data,
headers: { 'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8' }
}
return this.ApiService
.delete(`wis`, query, config)
.then((response) => response)
}