0

I simply call $.getSCript(location.href) and it gets the script properly, however if the file is not there (and that is what I am planning to do a lot) it prints an error GET (url) 500 (Internal Server Error)

How to prevent that from happening? How to get rid of error message?

babaleh
  • 1
  • 1

1 Answers1

0

Have you tried including an empty fail event?

$.getScript(SOME_LOCATION)
.done(function(script, textStatus) {
  // Whatever...
})
.fail(function(jqxhr, settings, exception) {
  // Just leave this empty
});

Alternatively, you can check if the URL is valid before using getScript, as described in the answer here: Checking a Url in Jquery/Javascript

Community
  • 1
  • 1
Assaf Hershko
  • 1,846
  • 4
  • 18
  • 20
  • I did try empty `.fail()` and it didn't work. I also cannot use checking url, because calling on location.href in `$.ajax({url:location.href})` is not the same as in `$.getScript(location.href)` so I would have to worry about stripping down get parameters – babaleh Jul 24 '13 at 22:45