1、有过这样一段代码,是ajax

$.ajax({
url: "http://127.0.0.1:9001",
type: "POST",
data: JSON.stringify({"reqMsg":"12345"}),
dataType: 'json',
timeout: 1000 * 30,
success: function (response) {
if(response.n=='6'){
dosomething();
init();
}else if(response.n=='3'){
init();
}
},
error: function(xhr, type){
init();
}
});

2、在谷歌、IE11等浏览器测试没有问题,但是碰巧客户现场是IE8,9这种浏览器,内网系统没办法升级。出现跨域ajax请求插件直接error的情况

3、解决方案在github上找到了解决办法,https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest    这个路径下表述了如何解决Cross-Domain AJAX for IE8 and IE9此类问题。

4、首先需要再页面引入 jquery.xdomainrequest.min.js

<script type="text/javascript" src="<%=basePath%>resources/js/jquery.min-1.9.1.js"></script>
<script type="text/javascript" src="<%=basePath%>resources/js/jquery.xdomainrequest.min.js"></script>

5、然后再正常写ajax之前,加上一句jQuery.support.cors = true;

jQuery.support.cors = true;
$.ajax({
url: "http://127.0.0.1:9001",
type: "POST",
data: JSON.stringify({"reqMsg":"12345"}),
dataType: 'json',
timeout: 1000 * 30,
success: function (response) {
if(response.n=='6'){
dosomething();
init();
}else if(response.n=='3'){
init();
}
},
error: function(xhr, type){
init();
}
});

6、这样就解决了。最后附上jquery.xdomainrequest.min.js 源码

/*!
* jQuery-ajaxTransport-XDomainRequest - v1.0.3 - 2014-06-06
* https://github.com/MoonScript/jQuery-ajaxTransport-XDomainRequest
* Copyright (c) 2014 Jason Moon (@JSONMOON)
* Licensed MIT (/blob/master/LICENSE.txt)
*/
(function(a){if(typeof define==='function'&&define.amd){define(['jquery'],a)}else if(typeof exports==='object'){module.exports=a(require('jquery'))}else{a(jQuery)}}(function($){if($.support.cors||!$.ajaxTransport||!window.XDomainRequest){return}var n=/^https?:\/\//i;var o=/^get|post$/i;var p=new RegExp('^'+location.protocol,'i');$.ajaxTransport('* text html xml json',function(j,k,l){if(!j.crossDomain||!j.async||!o.test(j.type)||!n.test(j.url)||!p.test(j.url)){return}var m=null;return{send:function(f,g){var h='';var i=(k.dataType||'').toLowerCase();m=new XDomainRequest();if(/^\d+$/.test(k.timeout)){m.timeout=k.timeout}m.ontimeout=function(){g(500,'timeout')};m.onload=function(){var a='Content-Length: '+m.responseText.length+'\r\nContent-Type: '+m.contentType;var b={code:200,message:'success'};var c={text:m.responseText};try{if(i==='html'||/text\/html/i.test(m.contentType)){c.html=m.responseText}else if(i==='json'||(i!=='text'&&/\/json/i.test(m.contentType))){try{c.json=$.parseJSON(m.responseText)}catch(e){b.code=500;b.message='parseerror'}}else if(i==='xml'||(i!=='text'&&/\/xml/i.test(m.contentType))){var d=new ActiveXObject('Microsoft.XMLDOM');d.async=false;try{d.loadXML(m.responseText)}catch(e){d=undefined}if(!d||!d.documentElement||d.getElementsByTagName('parsererror').length){b.code=500;b.message='parseerror';throw'Invalid XML: '+m.responseText;}c.xml=d}}catch(parseMessage){throw parseMessage;}finally{g(b.code,b.message,c,a)}};m.onprogress=function(){};m.onerror=function(){g(500,'error',{text:m.responseText})};if(k.data){h=($.type(k.data)==='string')?k.data:$.param(k.data)}m.open(j.type,j.url);m.send(h)},abort:function(){if(m){m.abort()}}}})}));

最新文章

  1. ActiveMQ第三弹:在Spring中使用内置的Message Broker
  2. maven初试2
  3. flex编译命令相关
  4. 如何在Ubuntu下使用TF/SD 卡制作Exynos 4412 u-boot启动盘
  5. Spring(3.2.3) - Beans(4): p-namespace &amp; c-namespace
  6. 在 iOS 8 中使用模糊效果
  7. hdu4585 &amp;amp; BestCoder Round #1 项目管理(vector应用)
  8. ExecutorService 建立一个多线程的线程池的步骤
  9. MySQL 导出命令
  10. 【转载】从头编写 asp.net core 2.0 web api 基础框架 (1)
  11. 树莓派linux系统连接windows7系统中的共享文件夹的正确姿势
  12. rt-thread之 for (fn_ptr = &amp;__rt_init_rti_board_start; fn_ptr &lt; &amp;__rt_init_rti_board_end; fn_ptr++) 理解
  13. 经典SQL面试题(转)
  14. JS-JS作用域问题
  15. [USACO 2010 Open Silver 3.Time Travel]——链表
  16. Python eval,exac,compile
  17. android Button、TabLayout英文自动改小写为大写的问题
  18. CDH上Cloudera Management Service 各个角色迁移至其他节点
  19. Cordova - 彻底搞定安卓中的微信支付插件!
  20. iOS-WebView(WKWebView)进度条

热门文章

  1. CentOS7.4 + Hadoop2.9安装配置管理(分布式)
  2. html5 audio vedio and video.js
  3. [EXCEL] 不能清除剪贴板: We couldn&#39;t free up space on the clipboard. Another program might be using it right now
  4. 避免重复插入数据sql server
  5. 18c新特性的一些小结(from JimmyHe)
  6. 泛微e-cology和Oracle无法启动的解决方案
  7. November 24th 2016 Week 48th Thursday
  8. fountion 的调用 和 打印返回值 + 占位符
  9. n=n+1 放在print(s)的上面的影响 (2) n=n=+1在前面,则不满足前面&lt;100条件时候,才跳出while的循环,这时候while循环结束, 到了外面的下一步--&gt;print()
  10. 【转】基于easyui开发Web版Activiti流程定制器详解(一)——目录结构