Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 稍后捕获jquery ajax错误_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 稍后捕获jquery ajax错误

Javascript 稍后捕获jquery ajax错误,javascript,jquery,ajax,Javascript,Jquery,Ajax,我尝试向一个免费邮箱发出http请求,我不知道它是否存在于法国以外 免费软件箱无法访问CORS请求,但她做了我想做的 例如,如果我请求电源: http://hd1.freebox.fr/pub/remote_control?code=5818260&key=power&long=false&repeat=1 freebox播放器启动,我有一个CORS错误: 无法加载XMLHttpRequest。请求的资源上不存在“Access Control Allow Origin”

我尝试向一个免费邮箱发出http请求,我不知道它是否存在于法国以外

免费软件箱无法访问CORS请求,但她做了我想做的

例如,如果我请求电源:

http://hd1.freebox.fr/pub/remote_control?code=5818260&key=power&long=false&repeat=1
freebox播放器启动,我有一个CORS错误:

无法加载XMLHttpRequest。请求的资源上不存在“Access Control Allow Origin”标头。因此,不允许访问源“null”

没关系,但是我会检查这个请求的http头,例如,如果我检查我的代码是否正确,freebox返回403表示错误代码

我尝试使用Jquery获取状态码:

            xhr = $.ajax({
            method: "GET",
            url: url,
            crossDomain: true,
            statusCode: {
                500: function () {
                    alert("Une erreur s'est produite !");
                },
                403: function(){
                    alert("aaaaa")
                    throw new badTelecommandeCode();
                },
                404: function(){
                    throw new freeboxNotFound();
                },
                0: function(){console.log(0)}
            },
            error: function (err) {
                console.log(err);
            }
        });
一直以来,状态代码都是0,错误不启动。我在控制台中遇到此错误:

无法加载XMLHttpRequest。请求的资源上不存在“Access Control Allow Origin”标头。因此,不允许访问源“null”。响应的HTTP状态代码为403

你可以看到这个答案的结尾

响应的HTTP状态代码为403。。 在jquery之前,用红色写一个错误:

我试图捕捉错误:

        try{
        xhr = $.ajax({
            method: "GET",
            url: url,
            crossDomain: true,
            statusCode: {
                500: function () {
                    alert("Une erreur s'est produite !");
                },
                403: function(){
                    alert("aaaaa")
                    throw new badTelecommandeCode();
                },
                404: function(){
                    throw new freeboxNotFound();
                }
            },
            error: function (err) {
                console.log(err);
            }
        });
    }
    catch(err){
        console.log(err);
    }
我已尝试搜索,其中错误已被jquery捕获:

http://code.jquery.com/jquery-2.1.4.js line 8634
您是否找到捕获CORS消息并对其进行解析的方法,或者捕获jquery消息,以及为什么不获取状态码或任何信息

对于小淘气者来说,向freebox开发者发送accept CORS请求的方式已经实现,但没有得到答复。我不能路过网络服务器

我目前面临的挑战是:我是lambda用户,可以看到我的电视,但我的免费电视遥控器不工作,我可以用我的智能手机/电脑轻松制作

更新1: 我举了一个例子:

如果效果良好:

    xhr = $.ajax({
    method: "GET",
    url: "http://hd1.freebox.fr/pub/remote_control?code=5818261&key=right&long=false&repeat=1",
    crossDomain: true,
    statusCode: {
        500: function () {
            alert("Une erreur s'est produite !");
        },
        403: function(){
            alert("badTelecommandeCode")
        },
        404: function(){
            alert("freeboxNotFound")
        }
    },
    error: function (err) {
        // console.log(err);
    },
    fail:function(jqxhr, textStatus, errorThrown) {
        // console.log(errorThrown);
    }
});
好的键,好的代码,我的电视做出动作,并返回一个CORS错误

如果代码不正确,或者密钥不存在,我将捕获:

        xhr = $.ajax({
    method: "GET",
    url: "http://hd1.freebox.fr/pub/remote_control?code=5818261&key=ping",
    crossDomain: true,
    statusCode: {
        500: function () {
            alert("Une erreur s'est produite !");
        },
        403: function(){
            alert("badTelecommandeCode")
        },
        404: function(){
            alert("freeboxNotFound")
        }
    },
    error: function (err) {
        // console.log(err);
    },
    fail:function(jqxhr, textStatus, errorThrown) {
        // console.log(errorThrown);
    }
});
xhr = $.ajax({
    method: "GET",
    url: "http://hd1.freebox.fr/pub/remote_control?code=222222&key=ping",
    crossDomain: true,
    statusCode: {
        500: function () {
            alert("Une erreur s'est produite !");
        },
        403: function(){
            alert("badTelecommandeCode")
        },
        404: function(){
            alert("freeboxNotFound")
        }
    },
    error: function (err) {
        // console.log(err);
    },
    fail:function(jqxhr, textStatus, errorThrown) {
        // console.log(errorThrown);
    }
});
我有一个CORS,没问题,但是我如何能捕捉文本,比如http状态

有关信息:
freebox.fr是一个NAT规则,重定向到我的路由器freebox,hdX.freebox.fr转到电视播放器的API高清数字X仍然不能正确解释问题。似乎没有从url返回响应。0似乎不是有效的HTTP响应代码,请参阅。错误被记录到控制台

根据以下要求

var xhr = new XMLHttpRequest();
 xhr.open("GET", "http://hd1.freebox.fr/pub/remote_control?code=5818260&key=power&long=false&repeat=1", true);
 xhr.onload = function() {
   console.log(this.status)
 }
 xhr.onerror = function(e) {
   console.log(e, this.status)
 }
 xhr.send();

您可以为此使用承诺检查:当请求为CORS且无法响应时,可能会发生错误状态0shared@BenjaminGruenbaum有什么例子吗?@AlfonsoGarnett是的,但是有东西在控制台中写入http状态,这样他就可以读取响应。。。我能赶上这个吗?我有相同的回报,如果它的工作与否:/,状态是0@thib3113什么是要求,预期结果?1-检查远程电视网络代码是否为http中的good code=XXX,如果无效但服务器不接受,则返回http错误403CORS@thib3113尝试打开新选项卡,在地址栏中键入http://hd1.freebox.fr/pub/remote_control?code=5818260&key=power&long=false&repeat=1,按enter键,打开控制台,查看网络选项卡?似乎没有从url返回响应?是的,这对我来说是可行的,但是,这不是我的问题,我会通过编程来实现,所以我已经更新了主题中当前的挑战。
GET http://hd1.freebox.fr/pub/remote_control?code=5818260&key=power&long=false&repeat=1 net::ERR_CONNECTION_TIMED_OUT 
var xhr = new XMLHttpRequest();
 xhr.open("GET", "http://hd1.freebox.fr/pub/remote_control?code=5818260&key=power&long=false&repeat=1", true);
 xhr.onload = function() {
   console.log(this.status)
 }
 xhr.onerror = function(e) {
   console.log(e, this.status)
 }
 xhr.send();