IE8 jquery跨域问题解决

1.IE8 jquery跨域问题解决: 加下面code

源地址: https://github.com/dkastner/jquery.iecors/blob/master/jquery.iecors.js

(function( jQuery ) {
  // Create the request object
  // (This is still attached to ajaxSettings for backward compatibility)
  jQuery.ajaxSettings.xdr = function() {
    return (window.XDomainRequest ? new window.XDomainRequest() : null);
  };

  // Determine support properties
  (function( xdr ) {
    jQuery.extend( jQuery.support, { iecors: !!xdr });
  })( jQuery.ajaxSettings.xdr() );

  // Create transport if the browser can provide an xdr
  if ( jQuery.support.iecors ) {

    jQuery.ajaxTransport(function( s ) {
      var callback,
        xdr = s.xdr();

      return {
        send: function( headers, complete ) {
          xdr.onload = function() {
            var headers = { ‘Content-Type‘: xdr.contentType };
            complete(200, ‘OK‘, { text: xdr.responseText }, headers);
          };

          // Apply custom fields if provided
					if ( s.xhrFields ) {
            xhr.onerror = s.xhrFields.error;
            xhr.ontimeout = s.xhrFields.timeout;
					}

          xdr.open( s.type, s.url );

          // XDR has no method for setting headers O_o

          xdr.send( ( s.hasContent && s.data ) || null );
        },

        abort: function() {
          xdr.abort();
        }
      };
    });
  }
})( jQuery );

 

2. IE8的internet 选项要启用  允许跨域

时间: 2024-08-06 12:19:15

IE8 jquery跨域问题解决的相关文章

jQuery跨域问题解决方法

跨域访问时web前端开发者经常遇到的问题,那么什么是跨域呢? 跨域的慨念: 只要协议,域名,端口任何一个不同,都被当作是不同的域.例如在A网站中,我们希望通过AJAX获得B网站中特定的内容,此时A网站和B位置不在同一个域,那么就出现了跨域访问问题.可以理解为两个域名之间不能跨国域名来发送请求或是请求数据,否则就是不安全的. 解决跨域访问的方法: 1.代理: 2.在服务器端设置相应的响应头: 3.JSONP. 接下来,我详细的介绍一下jQuery中的JSONP是如何解决跨域访问的. JSONP(J

jQuery 跨域访问问题解决方法

浏览器端跨域访问一直是个问题, 多数研发人员对待js的态度都是好了伤疤忘了疼,所以病发的时候,时不时地都要疼上一疼.记得很久以前使用iframe 加script domain 声明,yahoo js util 的方式解决二级域名跨域访问的问题. 时间过得好快,又被拉回js战场时, 跨域问题这个伤疤又开疼了. 好在,有jquery帮忙,跨域问题似乎没那么难缠了.这次也借此机会对跨域问题来给刨根问底,结合实际的开发项目,查阅了相关资料,算是解决了跨域问题..有必要记下来备忘. 跨域的安全限制都是指浏

JQuery跨域加载JSON数据或HTML。

前提:有时候需要在网页上,加载另一个网站上的数据.或者加载另一个网站上的一个页面.Js的Ajax请求不具备跨域功能,可以使用JQuery来实现. 网页端JS代码: $(function () { $.ajax({ type: "get", async: false, url: "http://localhost:13964/getpage.ashx?callback=?",//服务端URL,该URL返回一段JS数据.如需返回HTML,只需把HTML组织成JSON即可

jQuery 跨域访问的三种方式 No 'Access-Control-Allow-Origin' header is present on the reque

问题: XMLHttpRequest cannot load http://v.xxx.com. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. test.html:1 Resource interpreted as Script but transferred

jquery跨域访问解决方案

客户端“跨域访问”一直是一个头疼的问题,好在有jQuery帮忙,从jQuery-1.2以后跨域问题便迎刃而解.由于自己在项目中遇到跨域问题,借此机会对跨域问题来刨根问底,查阅了相关资料和自己的实践,算是解决了跨域问题.便记录下来,以供查阅.         jQuery.ajax()支持get方式的跨域,这其实是采用jsonp的方式来完成的.        真实案例:        $.ajax({             async:false,             url: 'http:

jquery跨域请求json数据

//服务端生成json数据json.php <?php $json=array("Volvo","BMW","SAAB"); $cb = $_GET['callback']; echo $cb.'('.json_encode($json, true).')'; ?> //客户端Ajax请求数据<script> $(document).ready(function() { var url="http://域名/js

jquery跨域调用wcf

使用jquery跨域调用wcf服务的时候会报如下错误 1 $.ajax({ 2 url: 'http://localhost:28207/Service1.svc/GetData', 3 method: 'get', 4 dataType: 'json', 5 data: { value: val }, 6 success: function (data) { 7 $("label").text("success: " + data); 8 }, 9 error:

js&amp;jquery跨域详解jsonp,jquery并发大量请求丢失回调bug

URL 说明 是否允许通信 http://www.a.com/a.js http://www.a.com/b.js 同一域名下 允许 http://www.a.com/lab/a.js http://www.a.com/script/b.js 同一域名下不同文件夹 允许 http://www.a.com:8000/a.js http://www.a.com/b.js 同一域名,不同端口 不允许 http://www.a.com/a.js https://www.a.com/b.js 同一域名,不

jQuery跨域调用WebService

jQuery跨域调用WebService举例html: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=&quo