27.10.2015 Views

AJAX and PHP

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 />

<strong>AJAX</strong> Grid<br />

Data grids have always been one of the areas where web applications have had a serious<br />

disadvantage compared to desktop programs. The fact that the page needed a full reload when<br />

switching between grid pages, or when updating grid details, harmed the application from a<br />

usability point of view. Technically, fully reloading the page has bad effects as well, unnecessarily<br />

wasting network resources.<br />

But now you know there is a smarter solution to this problem. You can use <strong>AJAX</strong> to update the<br />

grid content without refreshing the page. You can keep your beautiful design in the client browser<br />

without even one page blink. Only the table data is refreshed, not the whole page.<br />

The novelty in this chapter is that we'll use Extensible Stylesheet Language Transformation<br />

(XSLT) T <strong>and</strong> XML Path Language (XPath) to generate the client output. XSLT <strong>and</strong> XPath are<br />

part of the Extensible Stylesheet Language (XSL) family. XSLT allows defining rules to<br />

transform an XML document to another format <strong>and</strong> XPath is a very powerful query language that<br />

allows performing searches <strong>and</strong> retrieving data from XML documents. When used to create web<br />

front ends, XSLT permits implementing a very flexible architecture, in which the server outputs<br />

the data in XML format, <strong>and</strong> that data is transformed to HTML using an XSL transformation. You<br />

can find an introduction to XSL in Appendix C at http://ajaxphp.packtpub.com, <strong>and</strong> a good<br />

description at http://en.wikipedia.org/wiki/Extensible_Stylesheet_Language.<br />

Note the XSL transformation can be applied at both client side <strong>and</strong> server side. The<br />

implementation in this chapter relies on client functionality to perform the<br />

transformation. This doesn't require any special features of the server, but it poses some<br />

constraints for the client. In Chapter 9, you will see how to apply the transformation at<br />

the server side using <strong>PHP</strong> functionality, in which case you require this feature to be<br />

enabled in <strong>PHP</strong>, but the solution works with any client, as the client receives directly the<br />

HTML code it is supposed to display.<br />

In this chapter, you'll use:<br />

• XSL to generate an HTML data grid based on XML data received from the server.<br />

• <strong>AJAX</strong> to implement the editable data grid. The user should be able to switch between<br />

product pages <strong>and</strong> edit product details without experiencing any page reloads.<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!