Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i trigger ajax error callback on success callback?

I'm looking for a way to trigger ajax error in success callback. i have tried to explain my problem code below:

$.ajax({
url: requestURL,
data: postData,
type: 'post',
success: function(response){
    if(response.Success){
        // do something
    }else{
        // request workflow fails in this case,
        // i have to trigger this ajax request's error callback
    }
},
error: function(){
    // do something on error case
},
dataType: 'json'
});
like image 242
Mehmet Fatih Yıldız Avatar asked Aug 31 '10 13:08

Mehmet Fatih Yıldız


1 Answers

var errorhandler = function(xhr, textStatus, error){
    // do something on error case
};

$.ajax({
   url: requestURL,
   data: postData,
   type: 'post',
   success: function(response){
       if(response.Success){
           // do something
       }else{
           errorhandler();
       }
   },
   error: errorhandler,
   dataType: 'json'
   });
like image 96
jAndy Avatar answered Sep 23 '22 11:09

jAndy