Announcement Announcement Module
No announcement yet.
$.getJSON() problem Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • $.getJSON() problem

    I am creating a spring mvc3.0 application.... i have the jquery-1.3.2.js added to the project.... I have the following javascript function which i call on the submit button click....

    function checkUser() { var uname=$('#username').val(); var pword=$('#password').val(); alert(uname); alert(pword);

    $.getJSON("login.html",{username: uname, password: pword},

    i am using spring mvc 3.0..... Following is the controller that i use...

    package com.web.controller;

    import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMap ping; import org.springframework.web.bind.annotation.RequestMet hod; import org.springframework.web.bind.annotation.RequestPar am; import org.springframework.web.bind.annotation.ResponseBo dy;

    public class LoginController
    public @ResponseBody String getLoginStatus(@RequestParam("username") String username, @RequestParam("password") String password)
    System.out.println("\n\nin login controller\n\n");
    if(username=="apoorvabade" & password=="apoorva123")
    return "Login successful!!!";
    return "Login failed";

    when i click on the submit button, the function corresponding to the /login.html action is not invoked.... i am using the DispatcherServlet to map the requests to the following....

    here is the spring-servlet.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns=""
    xmlns:xsi="" xmlns:context=""

    <context:component-scan base-package="com.web.controller" />

    <bean id="viewResolver"
    class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <property name="prefix">
    <property name="suffix">



    <!DOCTYPE web-app PUBLIC
    "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "" >

    <display-name>Spring Ajax Tutorial Project</display-name>



    Can anybody tell me the problem please?

  • #2
    Several applications can be created with the spring mvc 3.0 as the platform. The Jquery should be added to the application. The submit button has an associated function to it. Package com.web.controller is the controller used in the project. The submit button is not working properly. It is not able to invoke the login function associated with it, when it is clicked. The mapping is done using the DispatcherServlet. The code is also given for the verification.


    • #3
      Have you tried using an absolute path in your getJSON request? Does the page making the getJSON request reside in the same relative directory as your app where login.html will map to?


      • #4
        Are you crossing domains?

        Are you testing this functionality across domains? Remember for AJAX requests cross-domain calls are a bugger, you'll have to use jsonp request with jquery instead of a plain getJSON which just does a regular JSON ajax call over GET...