在Chrome jQuery的AJAX随机误差仅误差、Chrome、jQuery、AJAX

2023-09-10 13:41:37 作者:想吃糖糖

的问题摘要

通过窗体身份验证登录Chrome浏览器之后。着陆页面RETURNURL会报错我jQuery的AJAX没有击中服务器。该状态code = 0 消息=错误。 (几乎没有有用)。尝试过Firefox和不能够复制的问题,我开始认为Chrome是问题。清除缓存,关闭并重新打开不能解决。最近的文章中,我能找到的就是这个。 jQuery的阿贾克斯 - 状态code 0 然而,URL是相对的, /测试

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

另外一个SO文章: jQuery的阿贾克斯在Chrome的问题

较长的描述

我正在使用jQuery阿贾克斯错误。它与窗体身份验证登录后立即看来,登陆页面(RETURNURL),将JS错误。然后刷新页面(F5)后,该脚本将工作(主要)。即使不使用F 5,使用链接将允许对JS工作(主要)导航到相同的页面。所以后直接登录是我的主要测试的路径。

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.

我有次在那里航行或F5刷新不停止的错误。因此在开始段落中使用多数。

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

一天有点不能够找到一个坚实的理由通过研究,JS调试器中,code和各种方案简化后;我需要请求一些帮助。

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错误反馈

最我所知是0 和错误错误的信息。

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

软件和版本

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

使用浏览器,我也曾尝试清空缓存和CTRL + F5。

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

MVC 我有由保护的作用[授权(角色=管理员)] 禁用这个属性确实出现了解决我的问题,然后后来,没有。因此,如果任何先前的发言弄得不好意思。大声笑,短头发!

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();
}

任何JavaScript脚本文件不被保护的窗体身份验证的文件夹后面。

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

jQuery的doc.ready

我有我已经习惯了暂停调试,看看对象的内容的jQuery的错误事件。

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);
        });
    });

我有一个jQuery的方法,它加载采用下列事件。虽然followig脚本看起来像它会踩住服务器。还有就是定时逻辑来确保只命中每5秒。

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方法

这是我的ajax调用它很简单,只要我能做到这一点。

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.
            }
        });
    }

提琴手

当错误发生时,提琴手不显示GET请求,这意味着服务器没有打。另外,我把在行动断点调试确认操作不被打到。

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.

其他: 由于AJAX调用发生每隔5秒。虽然在页面上,看到的状态,0和无差错错误;我清空缓存并无需刷新页面,Chrome和Ajax请求开始工作。为了记录在案,我的镀铬缓存seetings被设置为尽可能少的缓存,因为我允许配置。

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.

推荐答案

这个问题似乎是与Chrome浏览器28如何处理缓存GET请求的错误。版本27工作正常,因为这样做在版本28 POST请求。

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.

您可以通过设置您的$就高速缓存属性设置为false()调用解决该问题。

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