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.

Chapter 9<br />

}<br />

// continue if the process is completed<br />

if (xmlHttp.readyState == 4)<br />

{<br />

// continue only if HTTP status is "OK"<br />

if (xmlHttp.status == 200)<br />

{<br />

try<br />

{<br />

displayFeed();<br />

}<br />

catch(e)<br />

{<br />

// display error message<br />

displayError(e.toString());<br />

}<br />

}<br />

else<br />

{<br />

displayError(xmlHttp.statusText);<br />

}<br />

}<br />

// Processes server's response<br />

function displayFeed()<br />

{<br />

// read server response as text, to check for errors<br />

var response = xmlHttp.responseText;<br />

// server error?<br />

if (response.indexOf("ERRNO") >= 0<br />

|| response.indexOf("error:") >= 0<br />

|| response.length == 0)<br />

throw(response.length == 0 ? "Void server response." : response);<br />

// hide the "Loading..." message upon feed retrieval<br />

document.getElementById("loading").style.display = "none";<br />

// append XSLed XML content to existing DOM structure<br />

var titlesContainer = document.getElementById("feedContainer");<br />

titlesContainer.innerHTML = response;<br />

// make the feed container visible<br />

document.getElementById("feedContainer").style.display = "block";<br />

// clear home page text<br />

document.getElementById("home").innerHTML = "";<br />

}<br />

9. Create a new file named rss_reader.css, <strong>and</strong> add this code to it:<br />

body<br />

{<br />

font-family: Arial, Helvetica, sans-serif;<br />

font-size: 12px;<br />

}<br />

h1<br />

{<br />

color: #ffffff;<br />

background-color: #3366CC;<br />

padding: 5px;<br />

}<br />

h2<br />

{<br />

margin-top: 0px;<br />

}<br />

h3<br />

{<br />

231<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!