0

I have the following code

var email = document.getElementById("email").value;
    $.post("/valid",{emailadd: email},function(data){
        alert(data);
    });

on the server I have the following:

@RequestMapping(value = "/valid", method=RequestMethod.POST)
public @ResponseBody Boolean checkValidEmail(@RequestParam("emailadd") String emailadd){
    return false;
}

Using firebug I can see that var email get the value but it skips past the alert function, what am i doing wrong?

3
  • Could it be that data is empty? Try alert("Result: " + data); Commented Nov 10, 2011 at 22:35
  • Thanks for replying, but it didn't work. Commented Nov 10, 2011 at 22:42
  • Can you see any response in firebug? Show it. Add error handler to your Ajax request. Check server logs. Commented Nov 10, 2011 at 22:44

3 Answers 3

1

i think the problem is that you don't return any response. You are returning false or true, but doesn't this just stops the checkValidEmail method?

Not sure how this works within spring, but cant you render some text as output and see if that's outputted?

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks that worked with a String output, any idea why the boolean value didn't get returned?
it expected to be a string/html. you could check if the post worked by setting the header on the response within your spring code an then check the statusText in your callback. function(data, statusText) the text will be "timeout", "error", "notmodified", "success" or "parsererror". See jQuery doc's for more info about statusText
0

It looks like to me that the call hasn't completed yet, so data won't be populated. You will need to add a callback handler for complete

    var email = document.getElementById("email").value;
        $.post("/valid",{emailadd: email},
            complete: function(data){
               alert(data);
            }
    });

1 Comment

complete isn't a function for $.post is it? I thought this was only for the $.ajax function
0

I don't see anything wrong with your code. Maybe a stupid question but are you sure that the URL is right ? What about the webapp and the controller in the path ?

As a side note : $("#email").val() would be more jQuery friendly to get the email :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.