XmlHttpRequest.onload not called

前端 未结 3 1979
星月不相逢
星月不相逢 2021-02-20 10:39

I\'m playing around with this XmlHttpRequest thing. In some tutorials and books, it is the onload function the one that is called when the request is d

3条回答
  •  醉梦人生
    2021-02-20 11:19

    IE has different method to create xmlhttprequest.

    function createCORSRequest(method, url) {
      var xhr = new XMLHttpRequest();
      if ("withCredentials" in xhr) {
    
        // Check if the XMLHttpRequest object has a "withCredentials" property.
        // "withCredentials" only exists on XMLHTTPRequest2 objects.
        xhr.open(method, url, true);
    
      } else if (typeof XDomainRequest != "undefined") {
    
        // Otherwise, check if XDomainRequest.
        // XDomainRequest only exists in IE, and is IE's way of making CORS requests.
        xhr = new XDomainRequest();
        xhr.open(method, url);
    
      } else {
    
        // Otherwise, CORS is not supported by the browser.
        xhr = null;
    
      }
      return xhr;
    };
    

    same this article:https://www.html5rocks.com/en/tutorials/cors/

提交回复
热议问题