11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 22 • CREATING AJAX-ENHANCED FEATURES WITH JQUERY AND <strong>PHP</strong>www.it-ebooks.infopublic directory on your server and referencing it from anywhere within your website’s tag likethis:However, because jQuery is such a widely used library, Google hosts the library on its contentdistribution <strong>net</strong>work (CDN) and offers an API which allows developers to reference the hosted libraryrather than maintain a separate copy. By referencing Google’s hosted version, you reduce your ownbandwidth costs and ultimately help your website to load faster because the user has probably alreadycached a copy of jQuery locally as the result of a visit to another website also using the Google CDN.Load jQuery from the Google CDN using the following snippet:google.load("jquery", "1");The 1 parameter passed as the second option to the load() method tells Google to reference themost recent stable 1.X version available. It’s also possible to reference specific releases; for instance ifyou’d like to use the most recent release in the 1.3 branch, pass 1.3. If you desire a minor point release,such as 1.3.2, pass that specific version number.A Simple ExampleLike native JavaScript code, you’re going to want to organize your jQuery code in a way that ensures itwon’t execute until the HTML page has finished loading into the client browser. Neglecting to do socould cause unexpected side effects because it’s possible the JavaScript will attempt to examine ormodify a page element which has not yet rendered. To prevent this from occurring, you’ll embed yourjQuery code within its ready event:$(document).ready(function() {alert("Your page is ready!");}Insert this code below the call to the google.load() method, making sure it is placed within the tags. Reload the page and you’ll be greeted with the alertbox presented in Figure 22-2.Figure 22-2. Displaying an alert box with jQuery440

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

Saved successfully!

Ooh no, something went wrong!