| How to handle mysql error inside ajax?
|
skoff

msg:4454572 | 1:15 pm on May 17, 2012 (gmt 0) | Hi! So here's my question! I have this code that I use and it's working perfectly to insert data in my db. I know that jquery/ajax will handle some error like if the page isnt found or timeout etc. However if there's an error on server side while doing the insert in my table in jquery/ajax it will be successful no matter what. I guess that I need to send back something to confirm that it was well done or not. But I have no clue how to do this? Any help would be appreciated! Thanks
$.ajax({ type: "POST", url: "process/subscribe_process.php", data: dataString, success: function() { $("#message").html("Everything's good!"); //I need something here to confirm if mysql_query was done or not }, error: function() { $("#message").html("Error!"); } });
|
Fotiman

msg:4454583 | 1:50 pm on May 17, 2012 (gmt 0) | You need to modify process/subscribe_process.php to return something. For example, here's some pseudo code: <?php // susbscribe_process.php // insert into database // if no problems // echo "success"; // else // echo "error"; ?>
|
| And then: $.ajax({ type: "POST", url: "process/subscribe_process.php", data: dataString, dataType: "text", success: function(data) { if (data == "success") { $("#message").html("Everything's good!"); } else { // there was an error } }, error: function() { $("#message").html("Error!"); } });
|
|
|
Fotiman

msg:4454584 | 1:51 pm on May 17, 2012 (gmt 0) | Note, where I have: // there was an error You would want to add code to handle that error
|
skoff

msg:4454600 | 2:14 pm on May 17, 2012 (gmt 0) | great! that's what I was missing! Thanks for your help
|
|
|