0

I would like to use success and run function only if has 200 status code I have see only this example:

 $.ajax ({
   success: function(data,textStatus,jqXHR){
     external();
   }
 )};

But i never see a really code example i would like the if status code is 200 is run an external function

P.S. before i tried to use easy success (without arguments) and error, but error worked also if the external file was ok..

Sorry for my english

Borja
  • 3,359
  • 7
  • 33
  • 66

1 Answers1

1

The success event is called when the request succeeds (documentation). The textStatus parameter should contain the string '200' or any other status number your server returned.

I hope the code you posted is partial: I don't see the url, method, etc. which should be passed as parameters to $.ajax.

Traveling Tech Guy
  • 27,194
  • 23
  • 111
  • 159
  • Yes yes is partial :) so i can write "success: function(textStatus)" and inside put "if (textStatus == '200') { external() }" ??? – Borja Apr 29 '16 at 00:20
  • No; sincet `textStatus` is the second parameter, you need to provide (at least) the data parameter as well (you don't need to use it): `success: function(data, status) {if(status === '200') {console.log('yay!');}}` – Traveling Tech Guy Apr 29 '16 at 00:23