I couldn’t get the POST value in servlet page. my previous question related to this question.How to get the data from ajax request in servlet page?
I need dataRequestObject value in my servlet page.
var dataRequestObject= {};
dataRequestObject= {mark:Mark,subject:English,language:C language,author:john};
var dataRequestHeader= {};
dataRequestHeader= {Username:uname,Password:pword,Domain:domain,WindowsUser:windowsuser};
$.ajax({
type:'POST',
url:'http://localhost:8090/SampleServlet1/serv', //calling servlet
cache:false,
headers:dataRequestHeader,
data:JSON.stringify(dataRequestObject),
success:function(){ alert("Request Done");},
error:function(xhr,ajaxOptions){
alert(xhr.status + " :: " + xhr.statusText);
}
});
Thanks in advance.
You shouldn’t send it as JSON string, but just as JS object. Change
by
and access the values in the servlet the usual way by the keys as present in JS object
Note that your servlet needs to run in the same domain, otherwise you hit the Same Origin Policy. If it’s actually running on the same domain, then I would not hardcode the domain in the JS code since it makes your code totally unportable. So replace
by
or
as well.