Pass data to database using javascript Onclick

后端 未结 3 1498
甜味超标
甜味超标 2021-01-16 14:32

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 o

3条回答
  •  我在风中等你
    2021-01-16 15:18

    The simplest example I can think of is this. Make your AJAX call in your if block like this:

    $.get('updatescore.php', {'score': '222'}, function(d) {
        alert('Hello from PHP: ' + d);
    });
    

    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.

提交回复
热议问题