80 likes | 304 Views
Using Ajax. Asynchronous JavaScript and XML. An example of AJAX. What Is Ajax?. beginnings of Ajax as used today started with the release of Internet Explorer 5 in 1999 XMLHttpRequest is the way to go, and there have been numerous frameworks written to simplify its use.
E N D
Using Ajax Asynchronous JavaScript and XML
What Is Ajax? • beginnings of Ajax as used today started with the release of Internet Explorer 5 in 1999 • XMLHttpRequest is the way to go, and there have been numerous frameworks written to simplify its use
Using XMLHttpRequest • IE 5: request = new ActiveXObject("Microsoft.XMLHTTP") • IE 6+: request = new ActiveXObject("Msxml2.XMLHTTP") • All others: request = new XMLHttpRequest() • Example 18-1. A cross-browser Ajax function • Table 18-1. An XMLHttpRequest object’s properties
Your First Ajax Program • Type in and save the code in Example 18-2 as urlpost.html • PHP half of the equation, which you can see in Example 18-3.
Using GET Instead of POST • Example 18-4 shows how you would achieve the same result as with Example 18-2, but using an Ajax GET request instead of POST. • To accompany this new document, it is necessary to modify the PHP program to respond to a GET request, as in Example 18-5, urlget.php
Sending XML Requests • modify the previous example document and PHP program to fetch some XML data. To do this, take a look at the PHP program first, xmlget.php, shown in Example 18-6. • to the HTML document, xmlget.html, shown in Example 18-7.
About XMLAn XML document • XML document will generally take the form of the RSS feed shown in Example 18-8. However, the beauty of XML is that this type of structure can be stored internally in a DOM tree (see Figure 18-3) to make it quickly searchable