if (!jQuery.support.cors && window.XDomainRequest) {
var httpRegEx = /^https?:\/\//i;
var getOrPostRegEx = /^get|post$/i;
var sameSchemeRegEx = new RegExp('^'+location.protocol, 'i');
var xmlRegEx = /\/xml/i; // ajaxTransport exists in jQuery 1.5+
jQuery.ajaxTransport('text html xml json', function(options, userOptions, jqXHR){
// XDomainRequests must be: asynchronous, GET or POST methods, HTTP or HTTPS protocol, and same scheme as calling page
if (options.crossDomain && options.async && getOrPostRegEx.test(options.type) && httpRegEx.test(userOptions.url) && sameSchemeRegEx.test(userOptions.url)) {
var xdr = null;
var userType = (userOptions.dataType||'').toLowerCase();
return {
send: function(headers, complete){
xdr = new XDomainRequest();
if (/^\d+$/.test(userOptions.timeout)) {
xdr.timeout = userOptions.timeout;
}
xdr.ontimeout = function(){
complete(500, 'timeout');
};
xdr.onload = function(){
var allResponseHeaders = 'Content-Length: ' + xdr.responseText.length + '\r\nContent-Type: ' + xdr.contentType;
var status = {
code: 200,
message: 'success'
};
var responses = {
text: xdr.responseText
}; try {
if (userType === 'json') {
try {
responses.json = JSON.parse(xdr.responseText);
} catch(e) {
status.code = 500;
status.message = 'parseerror';
//throw 'Invalid JSON: ' + xdr.responseText;
}
} else if ((userType === 'xml') || ((userType !== 'text') && xmlRegEx.test(xdr.contentType))) {
var doc = new ActiveXObject('Microsoft.XMLDOM');
doc.async = false;
try {
doc.loadXML(xdr.responseText);
} catch(e) {
doc = undefined;
}
if (!doc || !doc.documentElement || doc.getElementsByTagName('parsererror').length) {
status.code = 500;
status.message = 'parseerror';
throw 'Invalid XML: ' + xdr.responseText;
}
responses.xml = doc;
}
} catch(parseMessage) {
throw parseMessage;
} finally {
complete(status.code, status.message, responses, allResponseHeaders);
}
};
xdr.onerror = function(){
complete(500, 'error', {
text: xdr.responseText
});
};
xdr.open(options.type, options.url);
//xdr.send(userOptions.data);
xdr.send();
},
abort: function(){
if (xdr) {
xdr.abort();
}
}
};
}
});
};

add:  jQuery.support.cors = true;

最新文章

  1. Strus2第一次课:dom4j操作xml
  2. linux日常运维管理
  3. SQL Server 自增字段重置
  4. mysql之字符编码问题
  5. 初始化 Ubuntu Trusty 14.04
  6. eclipse JAVA实现AES的加密和解密算法
  7. c++实现类似Common Lisp的多参数加法和比较
  8. ASP.NET Core 2.0 : 三. 项目结构
  9. 大数据 --> 分布式服务框架Zookeeper
  10. sleep、yield、join方法简介与用法 sleep与wait区别 多线程中篇(十五)
  11. 树莓派pwm驱动好盈电调及伺服电机
  12. 线程等待(java)
  13. JavaAndroid项目结构
  14. 爬虫基础以及 re,BeatifulSoup,requests模块使用
  15. 01-spark基础
  16. DWZ(JUI) 教程 跨域请求 iframeNavTab
  17. Java代码度量分析工具:Designite简介
  18. linux命令:crontab命令(转)
  19. WPF性能调试系列 – 内存监测
  20. Oh My Fish! 让你的 Shell 漂亮起来

热门文章

  1. ubuntu ping响应慢的解决(转)
  2. Python基础-configparser和hashlib模块
  3. 虚拟化qemu-img的简单用法。
  4. IT basic knowledge
  5. BGP Basic Knowledge
  6. CSS3 animation-iteration-count:infinite
  7. docker commit
  8. 前端之 Ajax(补)
  9. 31 整数中1出现的次数(从1到n整数中1出现的次数)
  10. Java智能图表类库JChartLib使用介绍