Chrome浏览器的jQuery AJAX的失败,而不是跨域问题 [英] Chrome jQuery AJAX failing, not a cross-domain issue

查看:1322
本文介绍了Chrome浏览器的jQuery AJAX的失败,而不是跨域问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些简单的JS / jQuery的code键使AJAX调用抓住一些HTML和推入我的页面上一个div。这工作正常,在Firefox,但无法在Chrome浏览器。

I've got some simple JS/jQuery code to make an AJAX call to grab some HTML and shove it into a div on my page. This works fine in Firefox but fails in Chrome.

在Chrome浏览器的控制台,我可以看到以(失败),然后键入待定。

In the Chrome console I can see the AJAX request shown with a status text of "(failed)" and type "pending".

所有的搜索,我所做的搜查是与跨域问题。这不适合在这里,我在一个web服务器上运行这一点,有一个域名,不带附加端口号。

All the searching I've done has searched is relating to cross-domain issues. This doesn't fit here, I'm running this on a webserver, with a domain name, without a port number appended.

下面是我的code样品(你可以看到我最初尝试使用.load(),同样的问题):

Here's my code sample (you can see I was initially trying to use .load(), same problem):

$('#brochure2012navigation a').click(function(event)
{
    event.preventDefault();

    //$('#brochurePage').load($(this).attr('href'));

    $.ajax({
        url: $(this).attr('href'),
        dataType: 'html',
        success: function(html) {
            $('#brochurePage').html(html);
        },
        error: function (xhr, ajaxOptions, thrownError) {
            console.log(xhr);
            console.log(thrownError);
        },
    });
});

在Chrome的控制台登录XHR对象看起来是这样的:

In Chrome's console the logged xhr object looks like this:

Object {readyState: 0, setRequestHeader: function, getAllResponseHeaders: function, getResponseHeader: function, overrideMimeType: function…}
abort: function (a){a=a||"abort",p&&p.abort(a),w(0,a);return this}
always: function (){i.done.apply(i,arguments).fail.apply(i,arguments);return this}
complete: function (){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}return this}
done: function (){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}return this}
error: function (){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}return this}
fail: function (){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}return this}
getAllResponseHeaders: function (){return s===2?n:null}
getResponseHeader: function (a){var c;if(s===2){if(!o){o={};while(c=bG.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c}
isRejected: function (){return!!i}
isResolved: function (){return!!i}
overrideMimeType: function (a){s||(d.mimeType=a);return this}
pipe: function (a,b,c){return f.Deferred(function(d){f.each({done:[a,"resolve"],fail:[b,"reject"],progress:[c,"notify"]},function(a,b){var c=b[0],e=b[1],g;f.isFunction(c)?i[a](function(){g=c.apply(this,arguments),g&&f.isFunction(g.promise)?g.promise().then(d.resolve,d.reject,d.notify):d[e+"With"](this===i?d:this,[g])}):i[a](d[e])})}).promise()}
progress: function (){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}return this}
promise: function (a){if(a==null)a=h;else for(var b in h)a[b]=h[b];return a}
readyState: 0
responseText: ""
setRequestHeader: function (a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this}
state: function (){return e}
status: 0
statusCode: function (a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this}
statusText: "error"
success: function (){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}return this}
then: function (a,b,c){i.done(a).fail(b).progress(c);return this}
__proto__: Object

抱歉,这看起来有点凌乱,但我认为最重要的事情是0的状态。

Apologies that this looks a bit messy, but I think the important thing is the status of 0.

监控日志,请求不打我的服务器。

Monitoring the logs, the request isn't hitting my server.

我真的在这里难倒,我AP preciate任何帮助!

I'm really stumped here, I'd appreciate any help!

干杯, 铝

推荐答案

这是可能的Ajax调用被封锁的Chrome浏览器的AdBlock插件。

It is possible that the ajax call gets blocked by the AdBlock Chrome addon.

某些URL可能会受阻,基于对Adblock的黑名单的钥匙。 在DevTools网络选项卡,这样的请求被标记为失败,在状态挂起

Some URLs might get blocked, based on the keys on the adblock blacklist. On DevTools Network tab, such requests are marked as 'failed', in status 'pending'

这篇关于Chrome浏览器的jQuery AJAX的失败,而不是跨域问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆