views:

58

answers:

0

I think it's a common problem but I can't find any solution about this. For example: I'm building a AJAX Web system using Jquery(client js) and php(server side). All the ajax requests are sent to index.php, which checks if that session is valid or not. If the session is not valid, server side's php will output the login page; if the session is valid, it will output a valid XML file. Here are some parts of the js code:

$.ajax({
        type:"POST",
  url:"./index.php",
        data:{ajax_fetch:1,action:"fetch_sbw",networkType:nType,serverType:sType,graphType:gType,startTime:sTime,endTime:eTime},
  dataType:"xml",
  error:errHandler,
  success:srv_pri_plot  
  });
 function errHandler(xhr, statusText, error)
{
 if (xhr.status == "301")
 {
  window.location="./login.php";
 }
 else
 {
  $("body").append('<div class="ui-state-error ui-corner-all" id="error">Network down, try again later</div>');
 }
}

Now, for those exceptions: 1) HTTP server down (xhr.status = 0, statusText='error') 2) Session Time Out Redirect (xhr.status=200, statusText='parseerror'(because it's not a XML file)): xhr.responseText is a returned HTML file for the login page 3) Database SQL server down: (xhr.status=200, statusText='parseerror'(because it's not a XML file), xhr.reponseText is some die msg generated by php (database can't be connected etc.)

I wonder if there are some easy way to tell these exceptions apart in .ajax?