11.07.2015 Views

AJAX and PHP

AJAX and PHP

AJAX and PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Registration Successfull!&lt;&lt; Go back8. Create a file named validate.js. This file performs the client-side functionality,including the <strong>AJAX</strong> requests:// holds an instance of XMLHttpRequestvar xmlHttp = createXmlHttpRequestObject();// holds the remote server addressvar serverAddress = "validate.php";// when set to true, display detailed error messagesvar showErrors = true;// initialize the validation requests cachevar cache = new Array();// creates an XMLHttpRequest instancefunction createXmlHttpRequestObject(){// will store the reference to the XMLHttpRequest objectvar xmlHttp;// this should work for all browsers except IE6 <strong>and</strong> oldertry{// try to create XMLHttpRequest objectxmlHttp = new XMLHttpRequest();}catch(e){// assume IE6 or oldervar XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP");// try every id until one worksfor (var i=0; i

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

Saved successfully!

Ooh no, something went wrong!