27.10.2015 Views

AJAX and PHP

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

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

Server-Side Techniques with <strong>PHP</strong> <strong>and</strong> MySQL<br />

// catching potential errors with Firefox<br />

var rootNodeName = xmlResponse.documentElement.nodeName;<br />

if (rootNodeName == "parsererror")<br />

throw("Invalid XML structure:\n" + xmlHttp.responseText);<br />

// getting the root element (the document element)<br />

xmlRoot = xmlResponse.documentElement;<br />

// testing that we received the XML document we expect<br />

if (rootNodeName != "response" || !xmlRoot.firstChild)<br />

throw("Invalid XML structure:\n" + xmlHttp.responseText);<br />

// the value we need to display is the child of the root <br />

element<br />

responseText = xmlRoot.firstChild.data;<br />

// display the user message<br />

myDiv = document.getElementById("myDivElement");<br />

myDiv.innerHTML = "Server says the answer is: " + responseText;<br />

}<br />

4. Create a file called morephp.php:<br />

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

Saved successfully!

Ooh no, something went wrong!