Im sending a request with data as an array of objects:
[
{id: "1"},
{id: "2"},
{id: "3"}
]
im using JSON.stringify() and my req.body looks like this:
{ '{"id":"1"},{"id":"2"},{"id":"3"}': '' }
Now i want to loop through req.body and get all the ids so i can delete them from the SQL DB. Im using Sequelize. The back end:
exports.deleteIds = (req, res, next) => {
console.log(req.body)
//here should be loop so i can delete all the ids one by one.
Model.destroy({
where: {
id:
}
})
}
The post request (client):
let ids = []
//maybe here is the problem?
for (var i = 0; i < selectedRow.length; i++) {
ids.push({id:selectedData[i].id})
}
let Url = "/admin/deleteIds"
let data = JSON.stringify(ids)
event.preventDefault();
$.post(Url, data, function (data, status) {
}).done(function (res) {
if (res.ids.length == 0) {
$('#mainContent').html('<h1>0 users found</h1>')
}
})
.fail(function (err) {
console.log(err.responseJSON.message)
})