【问题标题】:DOMException: Failed to execute 'send' on 'XMLHttpRequest' on Chrome onlyDOMException:仅在 Chrome 上无法在“XMLHttpRequest”上执行“发送”
【发布时间】:2016-12-03 01:38:42
【问题描述】:

我正在尝试通过 ajax jQuery 的方法从跨域服务器检索 XML,控制台上出现以下错误消息:

DOMException: Failed to execute 'send' on 'XMLHttpRequest': Failed to load: 'http://foreign.domain/...'

带来这个错误的代码是:

var temp = $.ajax({
    url : url,
    async : false
    dataType : "xml",
    success : function(xml) {
        // irrelevant for the case
    },
    error : function(xhr, textStatus, error) {
        console.warn('An error occured while loading the following URL: "%s". Error message: %s', url, error);
    }
});

【问题讨论】:

    标签: jquery ajax xml google-chrome asynchronous


    【解决方案1】:

    问题是由指定的同步选项:

    async: false,
    

    这似乎在 Chrome 中不起作用,可能是因为 jQuery's ajax 方法的规范,它说:

    跨域请求和dataType: "jsonp" 请求不支持同步操作。

    奇怪的是,Firefox 和 Internet Explorer 似乎忽略了该规范,它们都执行 http 请求并返回 XML 结果。

    【讨论】:

      猜你喜欢
      • 2015-12-28
      • 2019-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多