It is necessary to transfer the following object to the Jersey web service in JSON format ..

The request must be an AJAX request ..

Do I need to convert to JSON before transferring?

JSON.stringify(user); ?

 function registerController(){ console.log("In the register"); var user = { username:document.getElementById("reg_user_name").value, firstname:document.getElementById("first_name").value, lastname:document.getElementById("last_name").value, userid:document.getElementById("user_id").value, password:document.getElementById("reg_password").value, email:document.getElementById("reg_email").value } registerHandler(user); } 

 function registerHandler(user){ var xhr = new XMLHttpRequest(); console.log("In the register"); xhr.onreadystatechange = function(){ if(xhr.readyState!=4 || xhr.status!=200){ return window.alert("Problems with the request"); } } xhr.open("POST","http://localhost:8080/CouponOnWeb/webappl/register",true); xhr.setRequestHeader("Content-Type", "application/json"); xhr.setRequestHeader("Content-Language", "en-US"); xhr.setRequestHeader("Accept","application/json;text/plain"); xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest"); xhr.send(user); } 

  • why not try? - Grundy
  • Well, if you need to send json, then you need to convert. It seems to be logical. - Alexey Shimanskyj
  • It is logical for understanding .. I am writing my first web service. Understandably, thanks. - Maks.Burkov

0