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.info■ Note An asynchronous event is capable of executing independently to the main application without blockingother events which may already be executing at the time the asynchronous event is initiated, or which may beginexecuting before the asynchronous event has completed.Thanks to great JavaScript libraries such as jQuery and native capabilities of languages such as <strong>PHP</strong>,much of the gory details involving initiating asynchronous communication and XML payloadconstruction and parsing are abstracted away from the developer. However, understanding exactly whatrole XML plays in making Ajax possible will no doubt help you to both write and debug the often opaquecode and communication process associated with creating Ajax-driven interfaces.When referring to XML in the context of Ajax, developers are usually referring to two distinctvariants:• A feature built into all mainstream browsers, the Document Object Model (DOM)is an interface that JavaScript uses to parse and manipulate the elements andcontent that comprises a web page. By accessing the DOM, JavaScript is capable ofaccessing and tweaking everything from content found in a standard HTML tagsuch as title to the attributes of highly customized elements identified by aparticular combination of IDs and class names. I’ll present several examples ofjQuery’s ability to access and manipulate the DOM in the next section.• Because Ajax often depends upon two disparate programming languages such asJavaScript and <strong>PHP</strong> that are unable to communicate directly with one another, it’snecessary to use some data format which can be both and parsed by the client andserver languages. JavaScript Object Notation (JSON) has emerged as the de factoformat for such purposes (although it’s possible to use other formats) thanks notonly to widespread support among many programming languages (JavaScript and<strong>PHP</strong> included), but also because it’s relatively easy for humans to decipher at aglance, as contrasted with often densely formatted XML-based alternatives.In summary, Ajax-centric features rely upon several technologies and data standards to functionproperly, including a server and client-side language, the DOM, and a data format (often JSON) capableof being understood by all parties involved in the process. To shed further light on the workflow andinvolved technologies, this process is diagrammed in Figure 22-1.438

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

Saved successfully!

Ooh no, something went wrong!