i have a 5 stars rating system, on javascript!!! bau i want to update mysql table, when clicking on stars!!! can somebody tell me how can i update the table!!! thanks. . .
+1
A:
Respond to a click by sending an ajax POST to the server. With Prototype, this might look like this:
document.observe('click', handleDocClick);
function handleDocClick(event) {
var star;
star = event.findElement('.star'); // <= assumes images have the class "star",
// use any CSS here you like
if (star) {
event.stop();
new Ajax.Request('some_url', {
parameters: {star: star.id},
onSuccess: handleSuccess,
onFailure: handleFailure
});
}
}
...and define handleSuccess
handleFailure
as you see fit. More on the unofficial wiki and in the API docs.
You can also use jQuery, YUI, Google Closure, and many many other tools, or use the XMLHttpRequest object itself directly.
That's the client side. On the server side, you'd have to have a page (PHP, JSP, servlet, ASP.Net, FastCGI, old CGI, Perl, Python, ...) that can receive HTTP POST
s and handle them by updating the underlying MySQL data.
T.J. Crowder
2010-03-12 16:30:01