11.07.2015 Views

AJAX and PHP

AJAX and PHP

AJAX and PHP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 4}}{// display error messagedisplayError(e.toString());}}else{// display error messagedisplayError(xmlHttp.statusText);}// read server's responsefunction readResponse(){// retrieve the server's responsevar response = xmlHttp.responseText;// server error?if (response.indexOf("ERRNO") >= 0|| response.indexOf("error:") >= 0|| response.length == 0)throw(response.length == 0 ? "Server error." : response);// get response in XML format (assume the response is valid XML)responseXml = xmlHttp.responseXML;// get the document elementxmlDoc = responseXml.documentElement;result = xmlDoc.getElementsByTagName("result")[0].firstChild.data;fieldID = xmlDoc.getElementsByTagName("fieldid")[0].firstChild.data;// find the HTML element that displays the errormessage = document.getElementById(fieldID + "Failed");// show the error or hide the errormessage.className = (result == "0") ? "error" : "hidden";// call validate() again, in case there are values left in the cachesetTimeout("validate();", 500);}// sets focus on the first field of the formfunction setFocus(){document.getElementById("txtUsername").focus();}9. It's time to add the business logic now. Start by creating config.php, with this codein it:10. Now create the error h<strong>and</strong>ler code in a file named error_h<strong>and</strong>ler.php:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!