ajax - Spring - POST parameters with vanilla javascript -


i'm trying make ajax call using plain javascript spring controller. call fails "required string parameter 'allowedroles' not present"

the controller:

@requestmapping(path = "/updateroles", method = requestmethod.post) public string updateroles(@requestparam("allowedroles") string allowedroles,  final map<string, object> model) {      return "services"; } 

and ajax call:

var xhttp; if (window.xmlhttprequest) {     // code modern browsers     xhttp = new xmlhttprequest(); } else {     // code ie6, ie5     xhttp = new activexobject("microsoft.xmlhttp"); } xhttp.open("post", "/services/updateroles", true); xhttp.setrequestheader("content-type", "application/json"); xhttp.send({"allowedroles":allowedroles}); 

i have tried

xhttp.send("allowedroles=" + allowedroles); 

but result same

try json:

//create json data var jsondata = {allowedroles: 'string allowed'}; var formattedjsondata = json.stringify(jsondata); //send xhttp.send(formattedjsondata); 

if want, can check data sure jsondata correct, ie:

  console.log(jsondata);   console.log(json.parse(formattedjsondata)); 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -