Php 将jQuery.ajax用于投票脚本。投票成功后如何更新MySQL数据库?

Php 将jQuery.ajax用于投票脚本。投票成功后如何更新MySQL数据库?,php,jquery,mysql,ajax,Php,Jquery,Mysql,Ajax,我想我必须在成功选项中加入一些东西。然而,我所拥有的并没有起作用 我在页面上声明此JS函数: <script type="text/javascript"> function performAjaxSubmission() { $.ajax({ url: 'addvotetotable.php', method: 'POST', data: { }, success:

我想我必须在成功选项中加入一些东西。然而,我所拥有的并没有起作用

我在页面上声明此JS函数:

<script type="text/javascript">
 function performAjaxSubmission() {
        $.ajax({
          url: 'addvotetotable.php',
          method: 'POST',
          data: {
          },
          success: function() {
          }
        });

      }
</script>
addvotetotable.php看起来像:


必须在ajax请求的“数据”中提供要存储在数据库中的值。然后您可以在php代码中使用$_POST[“something”],检查它是否有效。。。并返回您在success函数中处理过的f.e.html或json

<script type="text/javascript">

 function onSubmitVote() 
 {

        $.ajax({
          url: 'addvotetotable.php',
          method: 'POST',
          data: "theVoteValue=" + <read_your_vote_value_here>,
          success: function(result) {
          >>>return something in your addvotetotable.php which indicate success and show a message whether the vote was successful or not.<<<
          }
        });

        return false; // prevent submit if it is a submit-type button.

}
</script>

函数onSubmitVote()
{
$.ajax({
url:'addvotetotable.php',
方法:“POST”,
数据:“theVoteValue=“+,
成功:功能(结果){

>>>在addvotetotable.php中返回一些表示成功的信息,并显示投票是否成功的消息。嗯,这看起来非常递归…投票的ajax完成后,我真正需要做的就是运行addvotetotable.php。是否有其他方法在success函数中调用php文件?您通常会调用php us我不知道你为什么要对php文件执行请求,并且只在成功后才想做一些事情。我想你只是想用你想要存储的数据做一个请求,然后在成功后显示一些东西。你到底想做什么?我使用的是一个投票脚本,它使用ajax注册投票,而无需重新加载g页面。我注意到他们使用的ajax函数有一个成功函数。在那里,我想调用我的php文件在mysql数据库中注册投票。我想你不明白ajax是如何工作的。我已经更新了我的答案,使其更具体一些,希望这能帮助你。你给我的函数看起来很完美,但我该如何调用它呢投票ajax函数何时成功?成功:函数(){onSubmitVote();}我尝试了上述方法,但没有成功??
?php
// If user submitted vote give the user points and increment points counter

require_once("models/config.php");

//Check to see if there is a logged in user
    if(isUserLoggedIn()) { 
    $username_loggedin = $loggedInUser->display_username;
    }

    if (strlen($username_loggedin)) { 
    include_once "scripts/connect_to_mysql.php";
    $query = mysql_query("SELECT vote FROM points_settings WHERE id=1")or die (mysql_error());
    while($info = mysql_fetch_array($query)){

            $points_value=$info['vote'];
    }
     include_once "scripts/connect_to_mysql.php";
        $query = mysql_query("INSERT INTO points (id,username,action,points) VALUES ('','$username_loggedin','vote','$points_value')")or die (mysql_error

());
        include_once "scripts/connect_to_mysql.php";
        $query = mysql_query("UPDATE userCake_Users SET points=points + $points_value WHERE Username='$username_loggedin'")or die (mysql_error());
    }

    ?>
<script type="text/javascript">

 function onSubmitVote() 
 {

        $.ajax({
          url: 'addvotetotable.php',
          method: 'POST',
          data: "theVoteValue=" + <read_your_vote_value_here>,
          success: function(result) {
          >>>return something in your addvotetotable.php which indicate success and show a message whether the vote was successful or not.<<<
          }
        });

        return false; // prevent submit if it is a submit-type button.

}
</script>