跨域的jQuery阿贾克斯不工作在IE9

跨域的jQuery阿贾克斯不工作在IE9

本文介绍了跨域的jQuery阿贾克斯不工作在IE9的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图访​​问使用jQuery一个REST Web服务。这项服务已经得到了正确的访问控制 - 允许 - 产地设置为*根据萤火虫,有没有问题,浏览器/ Firefox的访问它。不过,在IE中这是行不通的。

I'm trying to access a REST web service using jQuery. The service has correctly got Access-Control-Allow-Origin set to * according to Firebug, and there are no problems accessing it with Chrome/Firefox. However, in IE it doesn't work.

我已经经历了很多这个问题,那些已经被公布在变化看,但至今没有任何解决方案都为我工作。

I've looked through plenty of the variations of this question that have already been posted, but so far none of the solutions have worked for me.

下面是我的code(简化了成功/失败功能的内容,便于阅读):

Here is my code (simplified the success/failure function contents for ease of reading):

$.support.cors = true;
$.ajax({
url: 'https://api.guildwars2.com/v1/maps.json?callback=?',
cache: false,
type: 'POST',
dataType: "jsonp",
success: function() { alert("Success!"); },
error: function() { alert('Failed!'); }
});

它也不会与GET作为类型,也不具有或不回调工作

It also doesn't work with 'GET' as the type, nor with or without the callback.

我自己也尝试使其工作没有jQuery和都没有成功:

I have also tried making it work without jQuery and haven't been successful:

var xdr = new XDomainRequest();
var url = "https://api.guildwars2.com/v1/maps.json?callback=?";
if(window.XDomainRequest)
{
    if(xdr)
    {
        xdr.onsuccess = function(){alert('Success!');};
        xdr.open("get",url);
        xdr.send();
    }
    else
    {
        alert('Failed!');
    }
}

任何意见,任何人都可以给我将是非常美联社preciated,因为我考虑干脆镜像使用file_get_contents()函数在PHP我自己的服务器上的Web服务,尽管这是最后的手段,因为它会吞噬了大量的带宽。

Any advice anybody could give me would be much appreciated, as I'm considering simply mirroring the web service using file_get_contents() in PHP on my own server, although that would be a last resort as it would gobble up a lot more bandwidth.

推荐答案

该插件解决了这个问题对我来说。

This plugin solved it for me.

https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest

这篇关于跨域的jQuery阿贾克斯不工作在IE9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 01:55