Handling errors in jQuery.getScript

前端 未结 6 825
陌清茗
陌清茗 2021-01-02 14:00

jQuery\'s getScript function doesn\'t seem to support an error callback function. I can\'t use the global ajax error handling code here, a local error function would be idea

6条回答
  •  独厮守ぢ
    2021-01-02 14:23

    jquery.ajax has a alternative way to handle error

    jQuery.ajax({
            type: "GET",
            url: 'http://www.example.com/script_test.js',
            dataType: "script",
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log('error ', errorThrown);
            },
            success:function(){
                console.log('success');
            }
        });
    

提交回复
热议问题