9

Summary of problem

After logging in with Chrome via Forms Authentication. The landing page as returnUrl will error my jQuery ajax without hitting the server. The status code = 0 and the message = "error". (Hardly useful). Having tried Firefox and not being able to replicate the problem, I am starting to think Chrome is the issue. Clearing caches, closing and reopening does not fix. The closest article i can find is this. jQuery Ajax - Status Code 0? However, the URL is relative, /Test

Another SO article: jquery ajax problem in chrome

Longer description

I am getting an error with jQuery ajax. It seems that immediately after logging in with forms authentication; the landing page (returnUrl), will JS error. Then after refreshing the page (F5), the script will work (mostly). Even if not using F5, navigating to the same page using a link will allow the JS to work (mostly). So straight after login is my main testing path.

Also, navigating in another tab to /Test action directly, works. The original tab still errors until i navigate or refresh it as mentioned.

I have had times where the navigating or f5 refresh does not stop the error. Thus the use of "mostly" in the opening paragraph.

After a day and a bit of not being able to find a solid reason through research, JS debugger, simplification of code and various scenarios; I need to request some help.

Javascript error feedback

The most I can gather is a status code of 0 and an error message of "error".

Software and versions

ASP.NET MVC 3
Chrome v28.0.1500.72 m
jQuery v1.8.3
AttributeRouting

With Chrome, I have also tried emptying the cache and CTRL+F5.

MVC
I have an action protected by an [Authorize(Roles = "Admin")] Disabling this attribute does appear to solve my problem and then later on, not. So, sorry if any earlier statements confused. lol, short on hair!

[GET("Test")]
public ActionResult Test()
{
    Console.WriteLine("Test");
    return new EmptyResult();
}

Any javascript script files are not behind a folder that is protected with forms authentication.

jQuery doc.ready

I have a jQuery error event which I have used to pause debugging on to see the contents of the objects.

//-- while I am using this method, I have also used the `error: ` 
//-- part of $.ajax with the same result.
    $(function ()
    {
        $(document).ajaxError(function (event, jqxhr, settings, exception)
        {
            Debug.Log("event: " + event);
            Debug.Log("jqxhr: " + jqxhr.responseText);
            Debug.Log("settings: " + settings);
            Debug.Log("exception: " + exception);
        });
    });

I have a jQuery method which loads using the following events. While the followig script looks like it would slam the server. There is timing logic to ensure it only hits every 5 seconds.

$(document).on('mousemove','*',function(e){ TestMethod(this,e,'mousemove');});

Javascript method

This is my ajax call which is as simple as I can make it.

   function TestMethod(sender, e, eventTrgger)
    {
        $.ajax(
        {
            type: "GET",
            url: '/Test',
            dataType: 'html',
            success: function (html)
            {
                //-- tested with nothing here.
            }
        });
    }

Fiddler

When the error occurs, Fiddler does not show a GET request, meaning the server is not hit. Also, I place a debugger breakpoint in the action confirms the action does not get hit.

Additional: Since the ajax call occurs every 5 seconds. While on the page and seeing status-0 and error-"error"; I clear the cache and without refreshing the page, chrome and the ajax request starts working. For the record, my chrome cache seetings are set to as little cache as I am allowed to configure.

3
  • The fact that removing AuthorizeAttribute makes it work, and the notion that "the server does not get hit" seems to be completely disjoint. Commented Jul 22, 2013 at 1:05
  • I disabled the attribute just now, but also navigated to the login form with a returnURL ready. The problem occurred. I updated the Q to indicate that after you read it.... trying so many different paths. Commented Jul 22, 2013 at 1:07
  • I'm having a very similar issue. Get requests break after a few page refreshes, and I think it has to do with the same problem. Is this fixed in Chrome 29? Commented Aug 24, 2013 at 6:29

1 Answer 1

8

The issue appears to be a bug with how Chrome 28 handles caching for GET requests. Version 27 works fine, as do POST requests in version 28.

You can workaround the issue by setting the 'cache' property to false in your $.ajax() call.

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

3 Comments

Well. So far so good! I will continue testing it today. I have replaced my console.log with an Alert. So I will know soon enough if this solution works. Cheers for finding it. Perhaps a hyperlink to the issue could be added to the answer?
Just had this issue in 29.0.1547.65 on a mac, http 0 in response to $.post calls (so definitely http post). Charles showed no http request. Started debugging through jquery trying to find out if there was an underlying error on the xhr. Drove me crazy for a while, but eventually just added ?r=" + Math.random() to my URL (which was relative - /Keepalive.ashx) and the http statusCode 0 went away and all is working fine again.
I've just had this bug in chrome 29 too, it seems to be fixed in chrome 30. Setting cache to false fixed it in chrome 29 for me

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.