0

i am assigning an array to a key which need to be send in the payload of POST call in my angular js application. for example like below.

this.selectedCtlIds =[877, 982, 091, 112];

function saveFormSettings() {
 let data = this.settings; // have various key from the GET call
 data.statusIdToBeChanged = this.selectedCtlIds;
 console.log(data.statusIdToBeChanged, 'test '); // works fine

 Service.updateSettings(data).then(function (resp) {
  //POST CALL HERE
}

}


function updateSettings(param) {
    return $http({
        method: 'POST',
        url: url + '/setting',
        params: param
    })
}

expected payload by api is like statusIdToBeChanged: [877, 982, 091, 112]

instead it is passed like below when i checked in network payload

statusIdToBeChanged[]: 284
statusIdToBeChanged[]: 982
statusIdToBeChanged[]: 091
statusIdToBeChanged[]: 112

due to which the api is failing. i am not sure why it is like this in payload.

4
  • can you post the code of Service.updateSettings and your update call Commented Jul 21, 2022 at 10:42
  • in http post method pass data through body why params ? Commented Jul 21, 2022 at 11:10
  • if still you want through params then make it stringfy params: `${param}` Commented Jul 21, 2022 at 11:14
  • This seems like normal syntax to me: How to pass an array using $_POST?. Arrays show up with [] for every value. Or here: submitting html form values as array. If the API expects JSON, convert to JSON string first. Commented Jul 21, 2022 at 11:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.