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

在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.

posted @ 2015-09-01 18:22  不下  阅读(715)  评论(0编辑  收藏  举报