Posts Tagged ‘XML’

Tutorial: From PHP to XML to jQuery and Ajax

Wednesday, March 11th, 2009

Please Note: This article has been updated and reposted here

Back To Basics

So this is the first of many new tutorials I hope to provide under the new banner of “Back to Basics”. I hope to be able to provide high level tutorials to the beginner enabling you to take away key learning to build on, rather than give you everything in depth on a plate. I hope you find this insightful.

So today’s article will focus on getting data from a database using PHP, converting that to an XML document, and reading that XML in through jQuery via Ajax calls. Seems complex, but is in fact, very easy.

Database Design

This tutorial assumes you know how to connect to your database. It also assumes that you have a table setup called “people” with 3 columns: “title”, “firstname” and “surname”. Please enter some data into this table as it will be required.

The XML structure

So, the point of this tutorial is to read some XML with an Ajax call from jQuery, therefore we need to structure our data correctly. Here is an example of the structure our XML document will generate:

(more…)