I am trying to send token on server using Ajax post request. This is basic html code running separately http://localhost:56471
$.ajax({
type: 'POST',
url: 'http://localhost:8080/sometoken' ,
contentType: 'application/octet-stream; charset=utf-8',
success: function(result) {
// Handle or verify the server response.
console.log("Result is: " + result);
},
processData: false,
data: sometoken,
});
My servlet app running on port 8080 trying to get token
public void doPost(HttpServletRequest req, HttpServletResponse resp)throws IOException {
String name=req.getParameter("token");
response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");
}
I am totally new to servlet. This is my first servlet. Error I get when ajax post is called XMLHttpRequest cannot load http://localhost:8080/sometoken. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:56471' is therefore not allowed access.
Can anyone please help me how I can this post request without error?
Thanks