kk_gaurav
kk_gaurav

Reputation: 73

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

I am using jquery function $.getscript() to load 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

Upvotes: 0

Views: 2297

Answers (1)

mark-cs
mark-cs

Reputation: 4707

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

Upvotes: 1

Related Questions