views:

104

answers:

4

Yo.

I'm really quite new to this whole JavaScript business, not to mention AJAX, so I was thinking if you guys could help me out with a conundrum.

Basically, what I want is for the user to be notified upon a change in a value of a MySQL table. How should I go about that? Should I use jQuery, or can I slap something together myself?

Thankful for any and all replies.

A: 

You should use jQuery and jQuery ajax method http://api.jquery.com/jQuery.ajax/

Haris
+1  A: 

Well, this is a bit abstract, but there are two parts to this: a server-side script, and your AJAX code (which sends this request to the script). Your server-side script will actually be doing the query to see if the database has changed, so your JavaScript will have to have a periodic execution (say once every ten seconds or whatever interval is right for you) if you are not waiting for the user to refresh their page.

The chain of events will look something like this:

AJAX -> Script -> DB -> Script -> AJAX -> Update Web Page

You will definitely want to use jQuery, Prototype, or some similar framework if you are new to AJAX. It will save you tons of time.

Jeff Fohl
A: 

In the HTML page, the JavaScript will use AJAX to keep requesting a backend page during a certain interval. The backend page will check if a MySQL database was changed.

SHiNKiROU
+1  A: 

Depending on how quickly you need the users to be notified, you could use either polling (sending a request every X seconds to see if there's anything new) or use comet.

In any case, you'll need a server side programming language to be querying the database and serving the results, and you'll need some javascript on the client-side to be sending requests and displaying responses. I would highly recommend using the jQuery library, since it simplifies a lot of cross-browser incompatibility.

nickf