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 1All exercises from this book assume that you've installed your machine as shown inAppendix A. If you set up your environment differently you may need to implementvarious changes, such as using different folder names, <strong>and</strong> so on.Time for Action—Quickstart <strong>AJAX</strong>1. In Appendix A, you're instructed to set up a web server, <strong>and</strong> create a web-accessiblefolder called ajax to host all your code for this book. Under the ajax folder, create anew folder called quickstart.2. In the quickstart folder, create a file called index.html, <strong>and</strong> add the followingcode to it:<strong>AJAX</strong> with <strong>PHP</strong>: QuickstartServer wants to know your name:3. Create a new file called quickstart.js, <strong>and</strong> add the following code:// stores the reference to the XMLHttpRequest objectvar xmlHttp = createXmlHttpRequestObject();// retrieves the XMLHttpRequest objectfunction createXmlHttpRequestObject(){// will store the reference to the XMLHttpRequest objectvar xmlHttp;// if running Internet Explorerif(window.ActiveXObject){try{xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}catch (e){xmlHttp = false;}}// if running Mozilla or other browserselse{try{xmlHttp = new XMLHttpRequest();}catch (e){xmlHttp = false;}}// return the created object or display an error messageif (!xmlHttp)21

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

Saved successfully!

Ooh no, something went wrong!