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 6<br />

}<br />

{<br />

// try to create XMLHttpRequest object<br />

xmlHttp = new ActiveXObject(XmlHttpVersions[i]);<br />

}<br />

catch (e) {}<br />

}<br />

}<br />

// return the created object or display an error message<br />

if (!xmlHttp)<br />

alert("Error creating the XMLHttpRequest object.");<br />

else<br />

return xmlHttp;<br />

/* function that initializes the page */<br />

function init()<br />

{<br />

// retrieve the input control for the keyword<br />

var oKeyword = document.getElementById("keyword");<br />

// prevent browser from starting the autofill function<br />

oKeyword.setAttribute("autocomplete", "off");<br />

// reset the content of the keyword <strong>and</strong> set the focus on it<br />

oKeyword.value = "";<br />

oKeyword.focus();<br />

// set the timeout for checking updates in the keyword's value<br />

setTimeout("checkForChanges()", 500);<br />

}<br />

/* function that adds to a keyword an array of values */<br />

function addToCache(keyword, values)<br />

{<br />

// create a new array entry in the cache<br />

oCache[keyword] = new Array();<br />

// add all the values to the keyword's entry in the cache<br />

for(i=0; i=0; i--)<br />

{<br />

// compute the current prefix keyword<br />

var currentKeyword = keyword.substring(0, i+1);<br />

// check to see if we have the current prefix keyword in the cache<br />

if(oCache[currentKeyword])<br />

{<br />

// the current keyword's results already in the cache<br />

var cacheResults = oCache[currentKeyword];<br />

// the results matching the keyword in the current cache results<br />

var keywordResults = new Array();<br />

var keywordResultsSize = 0;<br />

// try to find all matching results starting with the current prefix<br />

for(j=0;j

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

Saved successfully!

Ooh no, something went wrong!