phpeveryday.com

The best tutorial of php, php framework, php strategies, object oriented oriented,


PHP - AJAX: Better Error Handler at Client Side

Tag:    Category: PHP Application
post: 18 Mar 2008 read: 128


PHP AJAX Step By Step Tutorial - part 9: Now, we modify our handle xml. We add better error handling function.

function handleXMLData()
{
 
  var xmlResponse = xmlHttp.responseXML;
  
  // error handling for IE and Opera
  if (!xmlResponse || !xmlResponse.documentElement){
    throw("1. Invalid XML Structure:\n " + xmlHttp.responseText);
  }
  
  var rootNodeName = xmlResponse.documentElement.nodeName;    
  //error handling for Firefox
  if (rootNodeName == "parseerror"){
    throw("2. Invalid XML Structure:\n " + xmlHttp.responseText);
  }

  var xmlRoot = xmlResponse.documentElement;
  
  if(rootNodeName != "datas" || !xmlRoot.firstChild){
    throw("3. Invalid XML Structure:\n " + xmlHttp.responseText);  
  }
  
  var xmlData = xmlRoot.firstChild;
  var dataNodeName = xmlData.nodeName;
  if (dataNodeName != "calculation"){
    throw("4. Invalid XML Structure:\n " + xmlHttp.responseText);    
  }
 
 myDiv = document.getElementById("myDivElement"); 
 myDiv.innerHTML += "Request status: 4 (complete). <br />Server said: "; 
 myDiv.innerHTML += xmlHttp.responseText;
 
}



| Give Your Opinion | Recommend
Share and Bookmark to: These icons link to social bookmarking sites where readers can share and discover new web pages.
digg del.icio.us technorati Ma.gnolia BlinkList

Recommended articles by other readers:
Web Services: How PHP Kiss VB.NET? (Part 1)
Chart: How to Build Cool Animation Real Time Chart
Joomla: Fast Road to Understand Component Programming
Email: Send Attachement Mail
CAPTCHA - part 3 : "Are you human or ....?" (Build Your CAPTCHA)

What do You Think?
Your Name *:
Email *:
(Will not be published)
Website/URL:
Your Comment *:
* Required


615
posting