Home > Store

Sams Teach Yourself Ajax, JavaScript, and PHP All in One

Register your product to gain access to bonus material or receive a coupon.

Sams Teach Yourself Ajax, JavaScript, and PHP All in One

Book

  • Sorry, this book is no longer in print.
Not for Sale

Description

  • Copyright 2009
  • Edition: 1st
  • Book
  • ISBN-10: 0-672-32965-4
  • ISBN-13: 978-0-672-32965-4

In just a short time, you can learn how to use Ajax, JavaScript, and PHP to create interactive interfaces to your web applications by combining these powerful technologies.

No previous Ajax programming experience is required. Using a straightforward, step-by-step approach, each lesson in this book builds on the previous ones, enabling you to learn the essentials of Ajax programming with JavaScript, PHP, and related technologies from the ground up.

Regardless of whether you run Linux, Windows, or Mac OS X, the enclosed CD includes a complete Ajax programming starter kit that gives you all the programming tools, reference information, JavaScript libraries, and server software you need to set up a stable environment for learning, testing, and production.

Learn how to…

  • Build better, more interactive interfaces for your web applications
  • Make JavaScript, HTML, XML, and PHP work together to create Ajax effects
  • Compile an Ajax application
  • Create and consume web services with SOAP and REST
  • Avoid common errors and troubleshoot programs
  • Use popular Ajax libraries to speed up and improve common programming tasks

On the CD

  • XAMPP for Windows, Mac OS X, and Linux—an easy-to-install package to set up a PHP- and MySQL-enabled Apache server on your computer
  • The jEdit programming editor for Windows, Mac, and Linux
  • Prototype, Scriptaculous, Rico, and XOAD—popular JavaScript libraries for creating Ajax applications and effects
  • A complete Ajax, HTML, XML, and PHP tutorial reference library in searchable PDF format
  • Source code for the examples in the book

Phil Ballard is a software engineering consultant and developer specializing in website and intranet design and development for an international portfolio of clients. He has an honors degree from the University of Leeds, England, and has worked for several years in commercial and managerial roles in the high technology sector.

Michael Moncur is a freelance webmaster and author. He runs a network of websites and has written several bestselling books about web development, networking, certification programs, and databases.

Category: Web Development

Covers: Ajax, JavaScript and PHP

User Level: Beginning–Intermediate 

Downloads

Downloads

Download the source code

Sample Content

Online Sample Chapter

Anatomy of an Ajax Application

Sample Pages

Download the sample pages (includes Chapter 3 and Index)

Table of Contents

Introduction

Part I: Web Basics Refresher                                                                         7

Chapter 1: Workings of the Web                                                               9

    A Short History of the Internet........................................................... 9

    The World Wide Web..................................................................... 10

    Introducing HTTP............................................................................ 14

    The HTTP Request and Response................................................... 15

    HTML Forms.................................................................................. 17

    Summary......................................................................................... 20

chapter 2: Writing and Styling Pages in HTML and CSS                         21

    Introducing HTML.......................................................................... 21

    Elements of an HTML Page............................................................. 23

    A More Advanced HTML Page...................................................... 27

    Some Useful HTML Tags................................................................ 29

    Adding Your Own Style.................................................................. 30

    Defining the Rules............................................................................ 31

    Add a Little class............................................................................. 31

    Applying Styles................................................................................ 33

    Formatting Text with Styles.............................................................. 35

    Adding Lines................................................................................... 39

    Summary......................................................................................... 40

Chapter 3: Anatomy of an Ajax Application                                             41

    The Need for Ajax.......................................................................... 41

    Introducing Ajax.............................................................................. 43

    The Constituent Parts of Ajax.......................................................... 45

    Putting It All Together...................................................................... 47

    Summary......................................................................................... 49

Part II: Introducing Web Scripting with JavaScript                                        51

chapter 4: Creating Simple Scripts in JavaScript                                      53

    Tools for Scripting........................................................................... 53

    Displaying Time with JavaScript....................................................... 54

    Beginning the Script......................................................................... 55

    Adding JavaScript Statements.......................................................... 55

    Creating Output............................................................................... 56

    Adding the Script to a Web Page..................................................... 57

    Testing the Script............................................................................. 58

    JavaScript Syntax Rules................................................................... 65

    Using Comments............................................................................. 66

    Best Practices for JavaScript............................................................ 67

    Summary......................................................................................... 69

chapter 5: Working with the Document Object Model (DOM)                71

    Understanding Objects.................................................................... 71

    Understanding the Document Object Model (DOM)........................ 72

    Working with Web Documents........................................................ 74

    Accessing Browser History.............................................................. 77

    Working with the location Object..................................................... 78

    Summary......................................................................................... 80

chapter 6: Using Variables, Strings, and Arrays                                       81

    Using Variables............................................................................... 81

    Understanding Expressions and Operators....................................... 85

    Data Types in JavaScript................................................................. 86

    Converting Between Data Types...................................................... 88

    Using String Objects........................................................................ 89

    Working with Substrings.................................................................. 92

    Using Numeric Arrays..................................................................... 94

    Using String Arrays.......................................................................... 96

    Sorting a Numeric Array.................................................................. 98

    Summary....................................................................................... 101

chapter 7: Using Functions and Objects                                                103

    Using Functions............................................................................. 103

    Introducing Objects....................................................................... 108

    Using Objects to Simplify Scripting................................................ 109

    Extending Built-in Objects.............................................................. 112

    Summary....................................................................................... 115

chapter 8: Controlling Flow with Conditions and Loops                         117

    The if Statement............................................................................. 118

    Using Shorthand Conditional Expressions....................................... 121

    Testing Multiple Conditions with if and else..................................... 122

    Using Multiple Conditions with switch............................................ 124

    Using for Loops............................................................................. 125

    Using while Loops......................................................................... 128

    Using do…while Loops................................................................. 128

    Working with Loops...................................................................... 129

    Looping Through Object Properties............................................... 131

    Summary....................................................................................... 134

chapter 9: Using Built-In Functions and Libraries                                   135

    Using the Math Object................................................................... 135

    Working with Math Functions........................................................ 137

    Using the with Keyword................................................................ 139

    Working with Dates....................................................................... 140

    Using Third-Party Libraries............................................................ 143

    Other Libraries.............................................................................. 144

    Summary....................................................................................... 145

Part III: Introducing Ajax                                                                           147

chapter 10: The Heart of Ajax–the XMLHTTPRequest Object           149

    Introducing XMLHTTPRequest..................................................... 149

    Creating the XMLHTTPRequest Object........................................ 150

    Summary....................................................................................... 156

chapter 11: Talking with the Server                                                       157

    Sending the Server Request........................................................... 157

    Monitoring Server Status............................................................... 162

    The Callback Function................................................................... 163

    Summary....................................................................................... 166

chapter 12: Using the Returned Data                                                     167

    The responseText and responseXML Properties............................ 167

    Parsing responseXML................................................................... 171

    Providing User Feedback.............................................................. 172

    Summary....................................................................................... 174

Chapter 13: Our First Ajax Application                                                  175

    Constructing the Ajax Application.................................................. 175

    The HTML Document................................................................... 176

    Adding JavaScript......................................................................... 177

    Putting It All Together.................................................................... 180

    Summary....................................................................................... 184

Part IV: Server-side Scripting with PHP                                                     185

Chapter 14: Getting to Know PHP                                                        187

    PHP Basics................................................................................... 187

    Your First PHP Script................................................................... 190

    Summary....................................................................................... 194

chapter 15: Variables                                                                            195

    Understanding Variables................................................................ 195

    Data Types.................................................................................... 197

    Working with Numbers.................................................................. 198

    Numeric Data Types...................................................................... 200

    Numeric Functions......................................................................... 200

    Working with Strings..................................................................... 202

    Formatting Strings.......................................................................... 203

    String Functions............................................................................. 205

    Working with Arrays..................................................................... 206

    Array Functions............................................................................. 208

    Date Formats................................................................................ 209

    Working with Timestamps.............................................................. 210

    Summary....................................................................................... 213

Chapter 16: Flow Control                                                                      215

    Conditional Statements.................................................................. 215

    Loops........................................................................................... 220

    Summary....................................................................................... 222

Chapter 17: Functions                                                                           223

    Using Functions............................................................................. 223

    Arguments and Return Values........................................................ 225

    Using Library Files......................................................................... 229

    Summary....................................................................................... 229

Chapter 18: Using Classes                                                                     231

    Object-Oriented PHP.................................................................... 231

    What Is a Class?........................................................................... 232

    Creating and Using Objects........................................................... 233

    Summary....................................................................................... 236

Part V: More Complex Ajax Technologies                                                 237

Chapter 19: Returning Data as Text                                                       239

    Getting More from the responseText Property................................ 239

    Summary....................................................................................... 245

Chapter 20: AHAH–Asynchronous HTML and HTTP                         247

    Introducing AHAH........................................................................ 247

    Creating a Small Library for AHAH............................................... 248

    Using myAHAHlib.js..................................................................... 250

    Summary....................................................................................... 255

Chapter 21: Returning Data as XML                                                      257

    Adding the “x” to Ajax................................................................... 257

    The responseXML Property.......................................................... 258

    Project–An RSS Headline Reader............................................... 262

    Summary....................................................................................... 269

chapter 22: Web Services and the REST and SOAP Protocols             271

    Introduction to Web Services......................................................... 271

    REST–Representational State Transfer......................................... 272

    Using REST in Practice.................................................................. 274

    Web Services Using SOAP........................................................... 278

    The SOAP Protocol...................................................................... 279

    Using Ajax and SOAP................................................................... 282

    Reviewing SOAP and REST.......................................................... 283

    Summary....................................................................................... 284

chapter 23: A JavaScript Library for Ajax                                             285

    An Ajax Library............................................................................ 285

    Reviewing myAHAHlib.js.............................................................. 286

    Implementing Our Library.............................................................. 287

    Using the Library........................................................................... 290

    Summary....................................................................................... 293

chapter 24: Ajax Gotchas                                                                     295

    Common Ajax Errors.................................................................... 295

    The Back Button........................................................................... 296

    Bookmarking and Links................................................................. 297

    Telling the User That Something Is Happening................................ 297

    Making Ajax Degrade Elegantly..................................................... 297

    Dealing with Search Engine Spiders................................................ 298

    Pointing Out Active Page Elements................................................. 299

    Don’t Use Ajax Where It’s Inappropriate...................................... 299

    Security......................................................................................... 300

    Test Code Across Multiple Platforms............................................. 300

    Ajax Won’t Cure a Bad Design..................................................... 301

    Some Programming Gotchas.......................................................... 301

    Summary....................................................................................... 302

Part VI: Ajax Tools and Resources                                                            303

Chapter 25: The prototype.js Toolkit                                                     305

    Introducing prototype.js................................................................. 305

    Wrapping XMLHTTPRequest–the Ajax Object........................... 308

    Example Project–Stock Price Reader.......................................... 311

    Summary....................................................................................... 313

chapter 26: Using Rico                                                                         315

    Introducing Rico............................................................................ 315

    Rico’s Other Interface Tools.......................................................... 320

    Summary....................................................................................... 324

Chapter 27: Using Script.aculo.us                                                          325

    Downloading the Library................................................................ 325

    Including the Files.......................................................................... 326

    Using Effects................................................................................. 326

    Building the Script.......................................................................... 327

    Summary....................................................................................... 329

Chapter 28: Using XOAD                                                                     331

    Introducing XOAD........................................................................ 331

    XOAD HTML.............................................................................. 334

    Advanced Programming with XOAD............................................. 337

    Summary....................................................................................... 338

Appendix: JavaScript, PHP, and Ajax Websites                                     339

Glossary                                                                                              343

TOC, 0672329654, 6/6/2008

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020