tags:

views:

23

answers:

1

I have a web application that I wrote using JQuery. I used the $.post methods throughout the application including the login screen. It was working fine and now suddenly out of the blue, it no longer works. The post response now returns null, however; if I manually type in the post, it returns the JSON code that I would expect.

A few things that might be helpful: 1.) I'm linking against the Google's hosting of JQuery. 2.) I have not made any changes to my code or site. It was working fine for about a week before this morning. 3.) Occasionally, the jquery post request does work. Especially when I'm slowly stepping through the code.

Here's a snippit of the code that's failing:

function TryLoggingIn()
{
$.post(
    "login.php",
    {action: "login", username: $("#_uxUsername").val(), password: $("#_uxPassword").val(), redirect: $("#_uxRedirect").val()},
    function(data)
    {
        if (data.response == "error")
        {
            $("#_uxErrorBox").slideUp();
            $("#_uxErrorBox").slideDown();
            $("#_uxErrorText").text(data.message);
            $(".widgetErrorIcon").show();
        }
        else
        {
            window.location = data.newlocation;
        }
    },
    "json"
 );

}

What's strange is that when it does fail and I'm watching it using WireShark, I never see the post request made, yet it enters the success function with data set to null.

+2  A: 

One thing to check, especially if WireShark isn't seeing any request, is whether the Ajax destination is being cached by your browser. One approach to prevent this is to append a meaningless querystring or anchor to your URL with a random number in it.

Firebug is also useful for this kind of thing, although using WireShark was a good idea also.

Lastly, it's often useful to rewrite your ajax call using jQuery.ajax() function rather than jQuery.post(), since that will allow you to tweak a lot more things, such as the timeout value, the "cache" flag, etc.

JacobM