I had a code, where an if
condition failed. In that case, I wanted the error:
part of the Ajax to get triggered. But everytime, the success:
of Ajax was called. Here is a code which can help you understand what I want to ask.
Ajax request call
success: function (response){
//some code
},
error: function (response){
//some code
},
In my backend code
if(condition ){
//some code
return response()->json([
'success'=>true,
'message'=>"Success: handler in Ajax should be triggered"
]);
}else{
//some code
return response()->json([
'success'=>false,
// OR 'error'=>true,
'message'=>"Error: handler in Ajax should be triggered"
]);
}
But, even if the condition
got false
, the success:
in Ajax was still triggered. It didn't go to the error:
part. I didn't understand. Can someone explain what was happening?