I am a real noob when it comes to javascript/ajax, so any help will be very appreciated. In reference to this question:
Updating a MySql database using PHP via an onClick javascript function
But mainly concerned with the answer left by Phill Sacre. I am wondering if someone could elaborate on how we are(if we can?) passing values/data through his example, using jquery. The code example left by him is as follows:
function updateScore(answer, correct) { if (answer == correct) { $.post('updatescore.php'); } } ... <a onclick='updateScore(this, correct)' ...> </a>
Say for example, we are wanting to pass any number of values to the database with php, could someone give me a snippet example of what is required in the javascript function? Or elaborate on what is posted above please?
Thanks again all.
The simplest example I can think of is this. Make your AJAX call in your if block like this:
On your ‘updatescore.php’ script, just do that: update the score. And return a plain text stating wether the update operation was successful or not.
Good luck.
P.S.: You could also use POST instead of GET.