Easy ajax with jQuery and PHP

March 29th, 2010

When I was first learning about web programming, it was difficult to grasp how javascript can interact with PHP.  How do I manipulate data in the database with a client-side language?  The answer, of course, is ajax, and if you’ve never used ajax, now is the time to learn how.

What is ajax?

Ajax is not a singular technology, it is a collection of technologies used for asynchronous communication between the client and server i.e. javascript grabbing data from a PHP script and displaying it on the page without refreshing the page.  This is done through a DOM api called XMLHttpRequest, and I would encourage you to read a more in-depth view on its Wikipedia page.  While this has some SEO implications, it also gives the programmer or designer a way to build rich, dynamic internet applications that don’t require a propriety plugin like Flash or Silverlight.  Now that you have a basic understanding of ajax, lets try it out.

In this tutorial and demonstration, I will take a number from the user with an input box, and grab the row with that ID from the database and display it.  This is not a useful example, but it does demonstrate the principles of moving data back and forth between the client and the server, and how we can display the data.

View the demo

Read the rest of this entry »