how callback a function on 404 on JSON ajax request with Jquery?

Posted by shingara on Stack Overflow See other posts from Stack Overflow or by shingara
Published on 2010-03-22T16:31:16Z Indexed on 2010/03/22 17:31 UTC
Read the original article Hit count: 532

Filed under:
|
|
|
|

I want made an Ajax request with response on JSON. So I made this Ajax request :

$.ajax({
    url: 'http://my_url',
    dataType: "json",
    success: function(data){
      alert('success');
    },
    error: function(data){
      alert('error');
    },
    complete: function(data) {
      alert('complete')
    }})

This code works good but when my url send me a HTTP code 404, no callbacks are used, even the complete callback. After research, it's because my dataType is 'json' so 404 return is HTML and the JSON parsing failed. So no callback.

Have you a solution to call a callback function when a 404 is raised ?

EDIT: complete callback don't call is return is 404. If you want an URL wit 404 you can call : http://twitter.com/status/user_timeline/jksqdlmjmsd.json?count=3&callback=jsonp1269278524295&_=1269278536697 it's with this URL I have my problem.

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about jquery-ajax