Chapter 10. Data retrieval


Most web sites are collections of HTML documents. These documents are connected by hyperlinks, and clicking on such links causes the browser to discard the old page and load the new one, a process that may take a few seconds.

This is fine as far as it goes, but occasionally you want a spiffier interface that doesn't change or flicker while new data is being fetched from the server, and where the new data is integrated seamlessly into the existing page. Usually this is called a Single Page Interface, since the users enter a certain page, and all actions they take result in new data being shown within that page.

From a JavaScript perspective, the question is one of data retrieval: how do you retrieve data from the server without reloading a page? Simple: you use the XMLHttpRequest object, which all modern browsers support.

Throughout this chapter we'll discuss XMLHTTP Speed Meter, since it's the only example script that uses data retrieval. Note from the outset, however, that it is the simplest possible data-retrieval script, because it fires just one data query. More complicated data-retrieval applications need many more features than this chapter discusses. After all, this book is not about application design, but about basic JavaScript.

Note that you're allowed to retrieve XML data files only from the same domain as the page. This is due to JavaScript's same-source policy, discussed in 1B.



ppk on JavaScript. Modern, Accessible, Unobtrusive JavaScript Explained by Means of Eight Real-World Example Scripts2006
ppk on JavaScript. Modern, Accessible, Unobtrusive JavaScript Explained by Means of Eight Real-World Example Scripts2006
ISBN: N/A
EAN: N/A
Year: 2005
Pages: 116

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net