[thelist] ajax example - php / mysql

Hassan Schroeder hassan.schroeder at gmail.com
Fri May 21 10:47:50 CDT 2010


On Thu, May 20, 2010 at 8:55 PM, Bob Meetin <bobm at dottedi.biz> wrote:

> ... in either case I'm not a JavaScript coder.
> At this point I would just like to see a couple simple working examples
> which interact with the database that I can tinker with.

It will definitely help to use one of those libraries to simplify making and
handling the response to the AJAX request.

It might also help to remember that it's *just a request* and you can
write and test the server side of it completely independently.

Decide what format you want your data to come back in: JSON, XML,
plain text, HTML snippet, whatever.

Create a PHP "page" that takes your request and any parameters,
fetches the data and formats it appropriately. View that page in your
browser; adjust as necessary. Now you're mostly done.  :-)

Look at your JS library's docs on how to generate an AJAX request.
It'll probably be something like (pseudocode)

AJAXRequest(url, method,
   params: { 'texture' = 'fuzzy' },
   success: { alert('it worked'); },
   error: { alert('aw rats'); })

where you can replace that "success" action with one to, say, replace
the contents of a paragraph with the received content. I'm not familiar
with MooTools documentation but look at the jQuery docs examples,
like <http://api.jquery.com/jQuery.get/>.

HTH,
-- 
Hassan Schroeder ------------------------ hassan.schroeder at gmail.com
twitter: @hassan


More information about the thelist mailing list