Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IE8和IE9跨域请求数据兼容性解决方案 #36

Open
youngwind opened this issue Mar 6, 2016 · 1 comment
Open

IE8和IE9跨域请求数据兼容性解决方案 #36

youngwind opened this issue Mar 6, 2016 · 1 comment

Comments

@youngwind
Copy link
Owner

原因

IE8和IE9在实现跨域请求的时候使用XDomainRequest自己实现了一套,所以即使是使用jquery1.9.1版本也无法直接兼容IE8,IE9的跨域请求。StackOverflow上的两个问答说得很清楚。

  1. http://stackoverflow.com/questions/24206782/ajax-call-not-working-in-ie8
  2. http://stackoverflow.com/questions/3362474/jquery-ajax-fails-in-ie-on-cross-domain-calls#11267937

解决方案

1. 自己抽象定义一个ajax请求函数

这个方法在上面第二个链接已经有人做好了,但是我嫌有点麻烦,不想在每个项目中都要定义这样一个函数吗?

2. 重定义jquery的$. ajaxTransport方法

有人已经做好了,详见这里。https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest

不过使用它有几点非常需要注意

  1. 只能是GET或者是POST请求
  2. POST请求的数据类型必须是text/plain
  3. 只支持HTPP和HTTPS协议
  4. 请求主体和被请求接口协议必须相同,也就是大家要么都是HTTP,要么都是HTTPS
  5. 必须是异步的
@cobish
Copy link

cobish commented Nov 20, 2017

jQuery-ajaxTransport-XDomainRequest 无法带上 cookies,oh my god...

tim 20171124170943

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants