当前位置:Gxlcms > 数据库问题 > iPhone Chrome&iPhone UC浏览器jsonp accept bug & h5 Access-Control-Allow-Origin跨域

iPhone Chrome&iPhone UC浏览器jsonp accept bug & h5 Access-Control-Allow-Origin跨域

时间:2021-07-01 10:21:17 帮助过:5人阅读

在iPhone 的chrome和UC浏览器中,当使用jsonp的形式跨域时,request的accept会是:*/*;image/webp。

在后端没有对content-type做特殊处理时,会直接返回 image/webp,这时,chrome和uc会无法执行jsonp返回的js。

 

解决方案:

1、放弃jsonp形式跨域、改用设置Access-Control-Allow-Origin

http://www.alloyteam.com/2012/11/html5-cors/?wpmp_switcher=mobile

2、需要cookie跨域时,

后端设置:

Access-Control-Allow-Credentials:true ,

ajax设置:

xhrFields: {
  withCredentials: true
}

需要注意,此时 Access-Control-Allow-Origin就不能设置为 *

不然报错如下:

XMLHttpRequest cannot load http://api.d.driver.edaijia.cn/workbench/userInfo?appkey=51000031&ver=3&met…11:16&ssid=u8srbnhpv2cogetnvaudrb3974&sig=61be8551eb4f8a8e3007ef748602df5e. A wildcard ‘*‘ cannot be used in the ‘Access-Control-Allow-Origin‘ header when the credentials flag is true. Origin ‘http://h5.d.edaijia.cn‘ is therefore not allowed access.

iPhone Chrome&iPhone UC浏览器jsonp accept bug & h5 Access-Control-Allow-Origin跨域

标签:

人气教程排行