我们正在开发一个使用
html5,jQuery(1.8.2)和jQuery mobile的移动网站,同时进行jQuery ajax调用(get和post).
在我们更改了域名后,我们对ie9的ajax调用进行“访问被拒绝”.
我们试图包含 jquery.iecors.js.但我们仍然得到同样的错误.这有什么解决方案吗?
在我们更改了域名后,我们对ie9的ajax调用进行“访问被拒绝”.
我们试图包含 jquery.iecors.js.但我们仍然得到同样的错误.这有什么解决方案吗?
示例代码:
$.support.cors = true; $.ajax({ cache: false,async: true,crossDomain: true,timeout: 600000,url: baseUrl + '/SmartTouch/restServices/PrefferedHotels',type: 'GET',beforeSend: function (xhr) { xhr.setRequestHeader("Authorization","Basic " + myencoded); },contentType: "application/x-www.form-urlencoded; (http://www.form-urlencoded;) (http://www.form-urlencoded;) charset=UTF-8",success: function (data) { alert("success"); },error: function (jqXHR,textStatus,errorThrown) { alert("error!!::" + JSON.stringify(jqXHR)); alert('response: ' + jqXHR.responseText); alert('code: ' + jqXHR.getResponseHeader('X-Subscriber-Status')); alert("textStatus " + textStatus); alert("errorThrown " + errorThrown); } });
编辑:
beforeSend: function (xhr) { xhr.setRequestHeader("Authorization","Basic " + myencoded); xhr.setRequestHeader("Access-Control-Allow-Origin","*"); xhr.setRequestHeader("Access-Control-Allow-Methods","POST,GET,OPTIONS"); },success: function (data) { alert("success"); },errorThrown) { alert("error!!::" + JSON.stringify(jqXHR));
IE9中的请求和响应标头:
Request: Key Value Request GET url HTTP/1.1 Accept text/html,application/xhtml+xml,*/* Accept-Language en-US User-Agent Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0) Accept-Encoding gzip,deflate Proxy-Connection Keep-Alive Host ("url") Pragma no-cache Cookie GUEST_LANGUAGE_ID=en_US; COOKIE_SUPPORT=true; __utmc=24444716; __utma=24444716.47018335.1379597653.1380274476.1380276859.17; __utmz=24444716.1379597653.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utmb=24444716.6.10.1380276859 Response: Key Value Response HTTP/1.1 200 OK Server Apache-Coyote/1.1 X-Powered-By Servlet 2.5; JBoss-5.0/JBossWeb-2.1 Accept-Ranges bytes ETag W/"64578-1380266616000" Last-Modified Fri,27 Sep 2013 07:23:36 GMT Content-Type text/html Date Fri,27 Sep 2013 10:17:01 GMT Content-Length 64578 Age 0 Via 1.1 localhost.localdomain
解决方法
这种Content-Type看起来很奇怪:
application/x-www.form-urlencoded; (http://www.form-urlencoded;) (http://www.form-urlencoded;) charset=UTF-8"
我可以想象IE有问题.
尝试正确的一个:
application/x-www-form-urlencoded; charset=UTF-8 ^-- notice: no dot!
IE也可能存在授权问题.
也许myencoded不在范围内或未正确填写.调试此变量并查看此问题:Authorization through setRequestHeader