I created a servlet in Eclipse IDE for Java EE that posts data as an XML page and hosted it on a Tomcat server. The servlet can be accessed at http://localhost:8080/Checkers/CheckersServlet. When I open this URL in Firefox, the XML loads correctly. Now, I'm trying to call the servlet from an AJAX code, but I seem to be encountering some issues.
It seems like the code snippet below should work, however, it's not functioning as expected. In my case, the problem lies in not receiving any XML from the servlet (where displayResult(req) is a custom function that processes the received XML).
Do I need to create one of those web.xml files? Or does Eclipse handle that automatically when I use the "new Servlet" option?
var req = new XMLHttpRequest();
req.onreadystatechange = function()
{
if(req.readyState == 4)
{
displayResult(req);
}
}
var url = "http://localhost:8080/Checkers/CheckersServlet";
req.open("GET",url,true);
req.send(null);