How can I use jQuery to run MySQL queries?

前端 未结 2 945
隐瞒了意图╮
隐瞒了意图╮ 2020-12-15 07:06

Is it possible to run a MySQL query using jQuery? I\'m trying to emulate the functionality of voting on SE sites.

The vote counter on SE automatically updates witho

2条回答
  •  一整个雨季
    2020-12-15 07:37

    It's just a few lines in your favorite language.

    Javascript

    $.post('script.php', { id: 12345 }, function(data) {
        // Increment vote count, etc
    });
    

    PHP (simplified)

    $id = intval($_POST['id']);
    mysql_query("UPDATE votes SET num = num + 1 WHERE id = $id");
    

    There are many different ways to accomplish this.

提交回复
热议问题