2017-12-22 1 views
0

どのように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) 
} 

==>で配列型のパラメータを送信するが、結果は次のとおりです。(不正なリクエスト!!)

リクエスト方法:

ステータスコードを削除します。 400 Bad Request

+0

ヘッダーを追加しようとしましたか? – Gautam

+0

はい私はそのヘッダーを追加しました:{'Content-Type': 'application/json; charset = utf-8'}しかし、同じ問題があったとしても、ヘッダーの値がわかりません –

+0

あなたのヘッダに何が渡されているかチェックしてください。 – Gautam

答えて

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) 
    } 
関連する問題