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 3}}// continue only if HTTP status is "OK"if (xmlHttp.status == 200){try{// do something with the response from the serverh<strong>and</strong>leServerResponse();}catch(e){// display error messagealert("Error reading the response: " + e.toString());}}else{// display status messagealert("There was a problem retrieving the data:\n" +xmlHttp.statusText);}// h<strong>and</strong>les the response received from the serverfunction h<strong>and</strong>leServerResponse(){// retrieve the server's responsevar response = xmlHttp.responseText;// obtain a reference to the element on the pagemyDiv = document.getElementById('myDivElement');// display the HTML outputmyDiv.innerHTML = "New r<strong>and</strong>om number retrieved from server: "+ response + "";}4. Load http://localhost/ajax/foundations/ping/ping.html. If you are usingInternet Explorer with the default options, you will be asked whether you will allowthe script to connect to a remote server as shown in Figure 3.8. If you are usingFirefox or Opera with the default options, you will get security errors like the onesshown in Figure 3.9 <strong>and</strong> Figure 3.10, respectively.Figure 3.8: Internet Explorer Asking for PermissionFigure 3.9: Firefox Denying Access83

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

Saved successfully!

Ooh no, something went wrong!