Jump to content

catching database error with ajax


stribor40

Recommended Posts

I have this snipped of code for my database connection

$res = odbc_exec($connection, $sql);
  if (!$res) {
    $arr = array('a' => 1);
    header('Content-type: application/json');
    echo json_encode($arr);
   } 

in my java script i have

......
...
success: function(data) {
	    if (data.a == 1){
		   $('#myidselector').html("<div><p>Somethign went wrong</p></div>");
	    }
		
},
.....
.....
....

now i am aware that there is error function for ajax but once when php code goes to line

odbc_exec($connection, $sql);

it spits out the error and execution stops and never gets to java script . All I want to do is handle database error gracefully. Does anyone have suggestions how to handle this.

Link to comment
https://forums.phpfreaks.com/topic/281258-catching-database-error-with-ajax/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.