Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why I can not pass parameter when http.delete in AngularJs?

I have function to call http.delete and pass a parameter flag:

function softDeleteDatasource(datasourceId,flag) {
            var url = baseUrl + datasourceId;
            return $http.delete(url, {'currentFieldSetFlag':flag});
        }

Then I assume I can get the req.body with following code. However, I always get undefined in the console.log. I used exactly same code in http.post and it works fine when passing parameter.

var bodyParser = require('body-parser');
var jsonParser = bodyParser.json();
router.delete('/:datasourceId', jsonParser, function(req, res) {
   console.log(req.body.currentFieldSetFlag);
}

I am confused why the same code can not pass parameter in http.delete? anyone know how to pass it?

like image 867
erkpwejropi Avatar asked Sep 27 '22 17:09

erkpwejropi


1 Answers

The HTTP spec allows for bodies on DELETEs, but some clients do not send them and some proxies/servers will strip/ignore them if present. This ought to work to pass it as a querystring parameter:

return $http.delete(url, {params: {'currentFieldSetFlag':flag}});
like image 127
jlew Avatar answered Oct 04 '22 18:10

jlew