22

In the documentation there is a list of possible values that textStatus might be if the error() callback fires ("timeout", "error", "notmodified" and "parsererror") but nothing specified for the success() event.

Are there any other values besides "success" that could be passed to the success() callback? Is this documented anywhere?

Robert
  • 6,660
  • 5
  • 39
  • 62

4 Answers4

8

Success can only be called on success. So the easy answer is no.

Complete will always run, regardless of what how ajax did. So complete should be able to get and values textstatus can return.

On the forum I found textstatus can be any of these values

"timeout"
"error"
"notmodified"
"success"
"parsererror"

http://forum.jquery.com/topic/jquery-ajax-textstatus-documented

Forge
  • 501
  • 2
  • 9
  • 6
    Your easy answer isn't quite right. The jQuery source does seem to show that the `success` callback will run if `notmodified` is returned. http://github.com/jquery/jquery/blob/master/src/ajax.js#L436 – user113716 Aug 11 '10 at 18:31
  • the answer should be updated as its not right and misleading. textStatus in success callback could take other values as described in other answers here – bilal.haider Oct 20 '16 at 15:36
7

Success and complete are documented at here. You don't really need to worry about what textStatus is passed to the functions, it's all handled automatically. The success function is called when/if the call succeeds, and complete is called at the very end of everything else.

So, as an example from something I'm working on, I chained together three functions that are triggered when you click a section of the page: a div fades out, and when that's done it runs an ajax call. The success function updates the content of the div (while it's faded out), and then the complete function calls fadeIn on the div. So what it does is it fades out, updates, and fades back in with new content.

Alex Zylman
  • 920
  • 1
  • 11
  • 20
  • 1
    That's the same documentation link I put in my question. `Complete` is called after `success` OR `error`, right? So `complete`'s textStatus could be "success" or any of the error codes. And some of the other answers indicate that `success` can be called with textStatus "notmodified". – Robert Aug 11 '10 at 18:47
  • 5
    Yeah, complete could be any of the possible textStatus codes. Success will only be success or notmodified. Notmodified is used when it just uses a cached version, most likely - though it seems weird to me that success would be called when you're essentially saying "hey, nothing changed". – Alex Zylman Aug 11 '10 at 18:53
  • 2
    Success can also be `nocontent`. jQuery 1.x can return `success` and jQuery 2.x can return `nocontent` for the exact same call. – cyberwombat Apr 16 '15 at 14:02
3

I don't see documentation per se, but you can find it in the source. Here's a nifty viewer.

http://james.padolsey.com/jquery/#v=1.4&fn=jQuery.ajax

Other possible values are "parsererror" and "notmodified".

Justin Force
  • 6,203
  • 5
  • 29
  • 39
2

From looking at the source it appears that notmodified could be a value, although I've never seen it.

Adam
  • 43,763
  • 16
  • 104
  • 144