I'm working on a project whereby in a JSP page I make an AJAX GET request to URL:
http://[domain]/ChatEngine/ChatServlet/users/login?roomId=0&name=Alan
This is pointing to a servlet I created named ChatServlet with my web.xml looking like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>ChatEngine</display-name>
<servlet> 
   <servlet-name>ChatEngine</servlet-name> 
   <servlet-class>com.tacticalenterprisesltd.chat.servlets.ChatServlet</servlet-class> 
</servlet>
<servlet-mapping> 
 <servlet-name>ChatEngine</servlet-name> 
 <url-pattern>/ChatServlet/*</url-pattern> 
</servlet-mapping> 
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>    
</welcome-file-list>
</web-app>
My index.jsp jquery AJAX code looks like this:
    var chaturl = "http://[domain]/ChatEngine/ChatServlet";
    var dataString = "roomId=" + roomID + "&name=" + uname;     
    $.ajax({
      type: "GET",
      url: chaturl + "/users/login", 
      data: dataString,
      contentType: "application/json; charset=utf-8",
      dataType: "json",
      cache: false,
      statusCode: {
          404: function() {
              console.log('404 Could not contact server.');
          },
          500: function() {
              console.log('500 A server-side error has occurred.');
          }
      },
      success: function(msg) {
          ...               
      },
      error: function(err) {
        alert('Login Error: ' + err.responseText + '  Status: ' + err.status + ' Response Status: ' + err.responseStatus); 
      }
    });
When I execute the AJAX request it keeps going immediately to the error property and I can't figure out why.
Here's the firebug readout:
 Notice how it says, "OPTIONS" instead of "GET".  I suspect that's a clue, but I don't understand why the browser is interpreting the request this way when I explicitly set the type attribute to "GET".
Notice how it says, "OPTIONS" instead of "GET".  I suspect that's a clue, but I don't understand why the browser is interpreting the request this way when I explicitly set the type attribute to "GET".
In the servlet, I wrote some println statements, but they aren't even being printed to the Eclipse console, so I know the servlet isn't even being called.
I know the URL is correct because I opened a new tab in FireFox, entered the URL into the address field, and immediately got a correct response from the servlet. So there's something screwy with the AJAX code. At this point I can't see the forest for the trees.
Please advise.
Alan
 
    