I build JQuery/JS/PHP/mySQL app with DB records management and need to provide reliable & complete feedback to the user on AJAX calls, modifying back end DB records. The problem IMHO is $.ajax success: and error: functions indicate just AJAX transport layer success and not the whole process. What if BD modification fails? How can one provide the complete feedback to the user?
I ended up with
$.ajax({ url: "/action/delete", data: "rowid="+rowid, complete: function(xmlHttp) { if ( xmlHttp.responseText ) alert('Success - back end returned "success"'); else alert('failure - back end returned NULL') } });
and PHP response:
$success = deleteRecord( $_GET(rowid) ); if($success) { print 'success'; } else { print NULL; } exit();
The idea is simple - if I manage to get positive feedback from the back end, then the whole operation succeeded, if not - user don't care where problem occurred.
Thank you in advance, your feedback is highly appreciated.