DOMException:仅在Chrome上执行'XMLHttpRequest'上的'发送'失败 [英] DOMException: Failed to execute 'send' on 'XMLHttpRequest' on Chrome only

查看:3584
本文介绍了DOMException:仅在Chrome上执行'XMLHttpRequest'上的'发送'失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to retrieve an XML from a cross-domain server via the ajax jQuery's method and the following error message appears on the console:


DOMException:未能在'XMLHttpRequest'上执行'send':无法加载:'http://foreign.domain / ...'

导致此错误的代码为:

The code that brings this error is:

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);
    }
});


推荐答案

问题是指定的同步选项:

The problem is the synchronous option specified by:

async: false,

这似乎不适用于Chrome,可能是因为 jQuery的ajax 方法,它说:

This seems not to work in Chrome probably because of the specification of the jQuery's ajax method, which says:


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

Cross-domain requests and dataType: "jsonp" requests do not support synchronous operation.

这种情况的奇怪之处在于Firefox和Internet Explorer似乎忽略了这个规范,并且它们都执行http请求并返回XML结果。

The strange of the situation is that Firefox and Internet Explorer seem to ignore that specification and they both perform the http request and return the XML result.

这篇关于DOMException:仅在Chrome上执行'XMLHttpRequest'上的'发送'失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆