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
精彩评论