开发者

how to handle file not found error in $.getscript()

开发者 https://www.devze.com 2023-03-11 03:39 出处:网络
I am using jquery function $.getscript() to load 开发者_JAVA百科script $.getScript(http:\\somedomain\\testscript.js, function() {

I am using jquery function $.getscript() to load 开发者_JAVA百科script

$.getScript(http:\somedomain\testscript.js, function() { //do some thing

}); Its works properly when testscript.js found but how can i handle error when file not found


From the JQuery API docs for getScript() you can see it is a wrapper for

$.ajax({
  url: url,
  dataType: 'script',
  success: success
});

So instead of using getScript() you could just use ajax() and use the complete method functionality:

complete(jqXHR, textStatus)Function, Array A function to be called when the request finishes (after success and error callbacks are executed). The function gets passed two arguments: The jqXHR (in jQuery 1.4.x, XMLHTTPRequest) object and a string categorizing the status of the request ("success", "notmodified", "error", "timeout", "abort", or "parsererror"). As of jQuery 1.5, the complete setting can accept an array of functions. Each function will be called in turn. This is an Ajax Event

0

精彩评论

暂无评论...
验证码 换一张
取 消