Handling errors in jQuery.getScript

前端 未结 6 853
陌清茗
陌清茗 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:24

    The global JQuery Ajax-ErrorHandler will work!

    Prior to the $.getScript-Call setup the Error Handler to cach the error.

    $(document).ajaxError(function(e, xhr, settings, exception) {
        alert('error in: ' + settings.url + ' \n'+'error:\n' + exception );
    });
    

    As described in the JQuery manual: http://api.jquery.com/ajaxError/.

提交回复
热议问题