你的位置:首页 > 软件开发 > Java > Ajax 在IE 9下跨域访问

Ajax 在IE 9下跨域访问

发布时间:2015-10-27 12:00:31
IE 9- XDomainRequest Domain Crossing Ajax Request.Backgroud:I had a problem on Ajax call for some data from an azure service in one of my pr ...

IE 9- XDomainRequest Domain Crossing Ajax Request.This is a sample of the usage of XDomainRequest: var requester = new XDomainRequest(); requester.open('get', 'another domain request url'); requester.contentType = 'text/plain'; requester.onload = function (event) { //get data from requester.responseText console.log('success'); }; requester.onerror = function () { console.log('error'); }; requester.send(); However, it may not work in your code. Because you may put this piece of code in one of page events. that's a problem. because there is a limitation of the usage of XDomainRequest. IE 9- asks you to initialize the XDomainRequest under a global scope instead of one event handle. For example, The code is wrong like this:$(function(){ var requester = new XDomainRequest(); requester.open('get', 'another domain request url'); requester.contentType = 'text/plain'; requester.onload = function (event) { //get data from requester.responseText console.log('success'); }; requester.onerror = function () { console.log('error'); }; requester.send(); });The correct way should be like this: var requester = new XDomainRequest();$(function(){ requester.open('get', 'another domain request url'); requester.contentType = 'text/plain'; requester.onload = function (event) { //get data from requester.responseText console.log('success'); }; requester.onerror = function () { console.log('error'); }; requester.send(); });This is the point i want to tell you here. Thanks.


 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:Ajax 在IE 9下跨域访问

关键词:ajax

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。