jQuery的ajaxSetup beforeSend不执行在IE8 [英] jQuery ajaxSetup beforeSend not executing in IE8

查看:2076
本文介绍了jQuery的ajaxSetup beforeSend不执行在IE8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目使用的jQuery 1.4.2。 我有我添加到我的AJAX头部中的一些安全信息... 我这样做的方法是使用$ .ajaxSetup(),并设置一个beforeSend功能。

My project uses jQuery 1.4.2. I've got some security information that I add to my AJAX headers... The way I'm doing this is by using $.ajaxSetup(), and setting a beforeSend function.

$(document).ready(function (e) {
    $.ajaxSetup({
        global: true,
        beforeSend: function (jqXHR, settings) {
            var verificationToken = 'some encrypted string';
            jqXHR.setRequestHeader("X-Request-Verification-Token", verificationToken);
        }
    });
})

据我所知,这应该然后执行每次我打电话到$阿贾克斯(),对不对? 它工作正常的Chrome浏览器,火狐,IE9,等等,但偶尔的没有的在IE7 / 8。

As I understand it, this should then execute every time I make a call to $.ajax(), right? It works fine in Chrome, Firefox, IE9, and so on, but occasionally not in IE7/8.

下面就是我把它叫做:

$.ajax({
    type: "POST",
    async: true,
    data: 'somedata',
    url: "/some/url",
    success: function (data) {
        alert("success");
    },
    error: function (data) {
        alert("error");
    }
});

我已经找到了解决办法,这是直接添加beforeSend到$阿贾克斯()调用(下同),但我真的想这样做全球性的,而不是必须将它添加到的地方,在负载code ...

I've found a workaround, which is to add the beforeSend directly to the $.ajax() call (below), but I really want to do this globally, rather than have to add it to loads of places in the code...

$.ajax({
    type: "POST",
    async: true,
    data: 'somedata',
    url: "/some/url",
    success: function (data) {
        alert("success");
    },
    error: function (data) {
        alert("error");
    }
    beforeSend: function (jqXHR, settings) {
        var verificationToken = 'some encrypted string';
        jqXHR.setRequestHeader("X-Request-Verification-Token", verificationToken);
    }
});

任何线索?

谢谢! 尼尔

推荐答案

好了,在没有任何其他的答案,我在此声明这是JQuery的1.4所支持的一个错误 解决的办法是升级到了jQuery,这可悲的是我不可能更高版本。

Ok, in the absence of any other answer, I hereby declare this to be a bug in JQuery 1.4.x. The solution is to upgrade to a later version of JQuery, which sadly isn't possible for me.

如果任何人有任何更好的答案/解决,我会高兴地删除这一条,并标记他们是正确的。

If anyone has any better answer/fix, I'll happily delete this one, and mark theirs as correct.

这篇关于jQuery的ajaxSetup beforeSend不执行在IE8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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