1

This is a followup to this question. Since the problem that I'm now facing is different from that, I thought I'll pose a new question.

I'm having an issue with the following code where in, the request is getting POSTed to the server, but whatever response the server has sent is not visible on the browser (in the form of an alert here).

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<script>
$(document).ready(function() {
    $('#login').delegate('input#submit','click',function(){
        var request = $.ajax({
            type: "POST",
            url: "login",
            data: {userid: $("#userid").val(), password:$("#password").val()},
            datatype: "xml",
            cache: false,
            success: function(xml){alert(xml);}
        });
    });
});

</script>

I can see that this request is going to the server - can see it in the logs. But I don't see the server's response in the browser. Here's the server's response:

<result><url>landing-page</url></result>

Not sure what am I doing wrong, but this seems to be simple stuff that I should get it working without issue. Tried Firebug, but no luck. Any idea as to where am I going wrong here or on how to debug this issue further.

Thanks

13
  • Can you show server side code . Also use console.log() in place of alert(). Does it return data in firebug ? Commented May 25, 2012 at 5:08
  • is any data appearing in the response headers visible in firebug/developer tools? Commented May 25, 2012 at 5:09
  • If you try this in Chrome and open the DevTools (Ctrl + Shift + I), you will see the Network tab. When you click on that, you can see all of the requests going out, and their responses. You should see one that says "login". If you click on it, does it have a response in the Response tab? Commented May 25, 2012 at 5:09
  • try changing this success: function(xml){alert(xml);} to success: function(data){alert(data);} Commented May 25, 2012 at 5:09
  • 1
    I don't think I have ever seen $.ajax assigned to a variable. I don't know for sure, but perhaps the success callback doesn't happen because the value is actually assigned to the variable. Try getting rid of the setting of var request Commented May 25, 2012 at 5:11

1 Answer 1

1

Either change your "success" callback to a "complete" callback, or add a complete callback. My guess is that it isn't detecting a "success" even though the response is being successfully retrieved. If it fires the "complete" callback, then you can try and fix your webservice to provide a successful response.

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

2 Comments

You are right, it helps if I change it to 'complete'. Do you know what the reason is that 'success' isn't responding?
It has to do with a header in your response on the server. I think that jQuery success callback is looking for a response code of 200. If your server doesn't have that... then I jQuery can't know...? I am not positive, but that is what I think is happening. If you look in the jQuery code, you will be able to see what it is looking for.

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.