Freakyuser
Freakyuser

Reputation: 2814

Using AJAX through Javascript to call a spring controller

I ain't able to open the controller's method

var url = "UsersGroupReader";
if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
}
req.onreadystatechange = processAccessGroupRequest;
req.open("GET", url, true); 
req.send(null);

My controller is:

@RequestMapping(value = "UsersGroupReader", method = RequestMethod.GET)
public Vector<String> readUsersGroup(HttpServletRequest request,
        HttpSession httpSession) {

The req.status I am receiving is 404 through AJAX.

The pattern in my web.xml is as follows:

<servlet-mapping>
    <servlet-name>login</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>

I tried using UsersGroupReader.html in both the AJAX function and the controller but still unable to access the controller.

Can anyone help me spot the mistake?
Could be a duplicate of this, in vain even after following it.

Thanks in Advance

Upvotes: 1

Views: 1580

Answers (1)

matt b
matt b

Reputation: 140051

It's likely that the request you are sending is either not being received by the intended server or that the DispatcherServlet is not being invoked for the request. To troubleshoot these type of issues you can usually find the actual cause by:

  1. Use your browser's developer toolbar to determine the exact URL being sent in the request.
  2. Turn up Spring's logging to debug to find out what it is doing when it receives the request (if it receives the request).
  3. Adjust the servlet-mapping accordingly.

Upvotes: 2

Related Questions