I am trying to figure out that how can I handle different responses sent from PHP to AJAX differently (I am using toastr for nice message display on front end). Say someone tried to insert some value into the database and the value got inserted successfully, then i sent I message from PHP by
echo "Data inserted";
and this gets caught by ajax response and gets handled by
success: function(response) {
toastr.success(response);
}
But I want that, when PHP sends a message something like
echo "Unable to insert data";
My AJAX handles it as an error and I want to use toastr.danger() instead of toastr.success().
How can I handle this situation ?