2

I am unable to catch a bad request error with my jquery code.

$.get('http://example.com/', {}, function () {}, 'jsonp') .done(function () { // never fires }) .fail(function () { // never fires }) .always(function () { // never fires }); 

I just get the error

GET http://example.com?callback=jQuery17102424617672804743_1366109250123&_=1366111087274 404 (Not Found)

2
  • Do you tried to open that link in browser and see the result? Does it show right data? Commented Apr 16, 2013 at 11:38
  • It shows my web host's 404 page which is what I expect. I want to catch for this 404 page when if my application ever goes down. Commented Apr 16, 2013 at 11:41

1 Answer 1

4

You can't use .get to call other domain. You need to make jsonp call with .ajax.

but it will be not enough to get error. Also you need to specify timout attribute. without it you will not get error.

$.ajax({ url: 'http://hq.am/asdasdasdasd?callback=?', timeout: 3000, dataType: "json", error: function(data){ alert('error'); } }); 

Sample

Sign up to request clarification or add additional context in comments.

1 Comment

Yes adding the timeout property did the trick. Thanks. (This also fires the fail() callback)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.