Skip to Main Content
Programming Atlas
book

Programming Atlas

by Christian Wenz
September 2006
Intermediate to advanced content levelIntermediate to advanced
408 pages
10h 38m
English
O'Reilly Media, Inc.
Content preview from Programming Atlas

Pure JavaScript

To conclude this chapter, it should also be mentioned that you do not even need Ajax to create Ajax-like effects. Or, to be more technically accurate, you do not need XMLHttpRequest to exchange data with the server. Using a bit of HTML knowledge and adding a bit of JavaScript to the mix, you can avoid the complexity of the various frameworks and just rely on your scripting knowledge.

The idea is to use a hidden frame to load another file in the browser, but in a way that the user does not see it. This new file contains JavaScript code that is created on the server and can therefore access server-side information. This code then changes some elements on the original page. This asynchronous approach has been quite common for several years, but without a fancy name like Ajax. This method avoids some of the browser incompatibility problems that made it so painful to create browser-agnostic web sites.

Figure 16-5 shows the concept: the code is loaded in either a hidden frame (<frame> element) or in an invisible iframe (<iframe> element). The latter option is preferable, because iframes can be embedded into a page. Then, the code in the iframe can change other HTML elements on the page.

Emulating Ajax without XMLHttpRequest

Figure 16-5. Emulating Ajax without XMLHttpRequest

First of all, an invisible iframe is required:

<iframe name="calculator" style="display: none;"></iframe>

As you can see, the iframe is ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Go Systems Programming

Go Systems Programming

Mihalis Tsoukalos

Publisher Resources

ISBN: 0596526725Supplemental ContentCatalog PageErrata