02.06.2013 Views

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

Pro PHP and jQuery by Jason Lengstorf.pdf - Computer Science ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

8<br />

CHAPTER 1 ■ INTRODUCING JQUERY<br />

Including a Remotely Hosted Copy of the <strong>jQuery</strong> Library<br />

The second option is to include a copy of the <strong>jQuery</strong> library hosted on Google Code. This is done in the<br />

hopes that visitors to your web site will have a copy of the library already cached from another site<br />

including the same file, which decreases load time for your site’s users.<br />

The remote copy is included just like the downloaded copy:<br />

<br />

<br />

Using the Google AJAX Libraries API<br />

Google Code also offers an option for loading <strong>jQuery</strong> called the AJAX Libraries API (see<br />

http://code.google.com/apis/ajaxlibs). In Google’s words, “The AJAX Libraries API is a content<br />

distribution network <strong>and</strong> loading architecture for the most popular, open source JavaScript libraries.”<br />

Using the AJAX Libraries API is simple <strong>and</strong> straightforward, <strong>and</strong> this is method that will be used<br />

throughout this book. To include <strong>jQuery</strong> in your web site using the AJAX Libraries API, use the following<br />

snippet:<br />

<br />

<br />

google.load("jquery", "1.4.2");<br />

<br />

Setting up a Test File<br />

Now that your testing environment is set up, create a new folder in the htdocs folder within your XAMPP<br />

installation called testing, <strong>and</strong> create a new file inside it called index.html. In the editor of your choice,<br />

insert the following HTML markup:<br />

<br />

<br />

<br />

Testing <strong>jQuery</strong><br />

<br />

<br />

Hello World!<br />

Another paragraph, but this one has a class.<br />

This is a span inside a paragraph.<br />

Paragraph with an id.<br />

And this sentence is in a span.<br />

<br />

<br />

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

Saved successfully!

Ooh no, something went wrong!