Catching same origin exception in Javascript?

一个人想着一个人 提交于 2019-12-06 00:01:52
xhr.onreadystatechange = function() {
    if (xhr.readyState==4) {
        if (xhr.status==0) {
            alert("denied");
        } else {
            alert("allowed");
        }
    }
}

Are you sure it's actually supposed to throw an exception? I can't see anything in the specifications: http://www.w3.org/TR/XMLHttpRequest/#exceptions Looks like it does. My bad.

In either case, you can always check the domain of the incoming string against the domain of the page the user is currently on.


FWIW, as you can see by this jsFiddle (open up Web Inspector), Chrome doesn't really throw an exception. It just says "Failed to load resource".

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!