JavaScript and Ajax

Cover of the book with purple, blue, and red squares.

JavaScript has nothing to do with Java. JavaScript was named Livescript until some marketing dweeb decided to cash in on the publicity that was surrounding Java back in the previous century.

JavaScript used to be too simple to do anything useful. Today JavaScript has grown to the point where it is very useful for Web pages. Thanks to Microsoft, JavaScript now has a simple powerful direct connection to your Web site; which lets you update pages the way interactive desktop applications update content. Microsoft's invention, the HTTP request function, is the bit that made Ajax possible.

JavaScript does not run on the Web server, which limits what JavaScript can do. You need
PHP on your Web server. With Ajax, JavaScript can talk to PHP on your Web server, PHP can perform powerful actions then send the result back to JavaScript for insertion into your Web page. Ajax gives JavaScript the power of PHP.

Contents

Chapters

  1. Getting Acquainted with JavaScript
  2. Start Me Up!
  3. Language Essentials
  4. Working with Images
  5. Frames, Frames, and More Frames
  6. Working with Browser Windows
  7. Form Handling
  8. Forms and Regular Expressions
  9. Handling Events
  10. JavaScript and Cookies
  11. Introducing CSS
  12. Objects and the DOM
  13. Making Your Pages Dynamic
  14. Applied JavaScript
  15. Introducing Ajax
  16. Ajax Toolkits
  17. Bookmarklets

Appendices

  1. JavaScript Genealogy and Reference
  2. JavaScript Reserved Words
  3. Cascading Style Sheets Reference
  4. Where to Learn More

JavaScript

The authors start of easily with basic JavaScript, how to write HTML that is friendly to JavaScript, and selecting an editor for your work. They get the JavaScript and HTML right but miss the best editors. Look at
NVU and jEdit when you are choosing an editor.

They proceed in a very logical order for developing your JavaScript skills. Early on they show alerts so you can display what is happening within JavaScript and they show how you can document JavaScript so you can constantly write notes about exactly what each line of code does, or is supposed to do. You can also use comments to keep track of each code variation you test; which gives you a guide to what will work in the future.

If you know HTML and have never used JavaScript; JavaScript is easier to learn from this book than from any JavaScript book I have used previously.

There is a chapter on frames that you can skip as frames are a bad idea. Frames let you update a small part of a page without updating a whole page but frames were poorly implemented from day one and where never fixed in any browser. Ajax provides a better, more flexible way to update parts of a Web page.

The book covers validating data within forms using JavaScript. Remember to validate the data again when the data reaches the Web server because people can bypass JavaScript.

There is a chapter on CSS, Cascading Style Sheets, which help you format Web pages, and JavaScript helps you highlight parts of your Web page by changing the use of CSS. When you see Web pages with text smeared over other text, that is CSS attempting but failing to position text. When you use CSS, test the result in a wide range of browsers.

The browser DOM, Document Object Model, is introduced and the most popular uses of the DOM are explained in detail.

There are practical applications of JavaScript at a level short of writing games. At this point, books focused purely on JavaScript show you how to write a game because there is little else that you would want to do with pure JavaScript. To progress beyond games, or to build great games, you need interaction with the Web server, you need Ajax.

Ajax

Ajax is based on JavaScript with an added HTTP request function that lets JavaScript talk directly with Web servers. The X in Ajax is for XML but a lot of Ajax is implemented using plain text instead of XML.

JavaScript can work only in the browser. Ajax lets JavaScript as the Web server for help. The Web server has to know what Ajax will request and have a way to get the answer. Ajax only works when you have compatible code on the Web server and that server code is usually written in PHP.

To make Ajax useful, you need to know PHP or know someone who knows PHP. You use PHP to write the web server scripts that talk with the browser based Ajax scripts. If you want to display the current weather on a Web page, you can use Ajax to update the weather every minute even if the visitor does not refresh the Web page. Ajax asks the web server for the latest weather report. A PHP script, on the Web server, hears the request, finds the weather report, converts the weather report to the right XML format, and sends the weather report back to Ajax in the browser.

The book uses an Ajax toolkit library from Yahoo.com. There are others and
jquery is one of the most popular Ajax libraries.

Alternatives

Ajax and REST Recipes: A Problem-Solution ApproachPractical JavaScript, DOM Scripting and Ajax ProjectsPro JavaScript Techniques

Conclusion

[amazon 0321564081 thumbnail]
Buy [amazon 0321564081 inline]. Learn to use Ajax. Look for an opportunity to use Ajax on your Web site. If you pay someone else to develop your Web site then buy the book for them.