jquery ajax jsonp跨域回调函数仅在IE7和以下版本中获取数据

时间:2022-12-08 19:48:07

I have two servers, one is localhost:3000, the other is gjy.com:3001,

我有两个服务器,一个是localhost:3000,另一个是gjy.com:3001,

gjy.com:3301 server side is expressjs.

3301服务器端是expressjs。

//app.js
app.get('/user/jsonp', user.jsonp);

//user.js
exports.jsonp = function(req, res) {
    res.jsonp({"name": "jsp"});
};

localhost:3000 the page JS function code is like below:

本地主机:3000页JS函数代码如下:

        $.ajax({
            type: 'GET',
            url: 'http://gjy.com:3001/user/jsonp',
            dataType: 'jsonp',
            crossDomain: true,
            success: function(data) {
                console.log('data is loaded');
                console.log(data);
            },
            error: function(err) {
                console.log('err');
                console.log(err);
            }
        });

and the console result in ie7 and below is

ie7和下面的控制台结果是

data is loaded
undefined

but the console result in other browsers

但是控制台会导致其他浏览器的出现

data is loaded
{"name": "jsp"}

1 个解决方案

#1


0  

In IE8 Microsoft implemented their own version of crossDomain, and rather than implementing the CORS version of XMLHttpRequest, the IE team went with their own propriety object, named XDomainRequest.

在IE8中,Microsoft实现了他们自己的crossDomain版本,而不是实现CORS版本的XMLHttpRequest, IE团队使用了自己的专有对象XDomainRequest。

jQuery patches this for IE8, but in IE7 there is no such method implented, so IE7 simply does not support cross domain calls, it's only supported in IE8 and up.

jQuery对IE8进行了补丁,但是在IE7中没有这样的方法,所以IE7不支持跨域调用,只支持IE8和以上版本。

#1


0  

In IE8 Microsoft implemented their own version of crossDomain, and rather than implementing the CORS version of XMLHttpRequest, the IE team went with their own propriety object, named XDomainRequest.

在IE8中,Microsoft实现了他们自己的crossDomain版本,而不是实现CORS版本的XMLHttpRequest, IE团队使用了自己的专有对象XDomainRequest。

jQuery patches this for IE8, but in IE7 there is no such method implented, so IE7 simply does not support cross domain calls, it's only supported in IE8 and up.

jQuery对IE8进行了补丁,但是在IE7中没有这样的方法,所以IE7不支持跨域调用,只支持IE8和以上版本。