如何使用 ajax 将 javascript 变量输入到 php 函数中


How do you input a javascript variable into php function using ajax?

我在这里做错了什么?一切正常,控制台中没有错误,但也没有控制台日志说它成功了

带有脚本的索引文件:

    <script type="text/javascript">
       function upVote(picNum)
          {
              var pictureNumber = parseInt($("#" + picNum).attr("id"));

              $.ajax({
                 url: "upload/pics/changeVote.php",
                 data: {"picNum":pictureNumber},
                 type:'post',
                 dataType:'json',
                 success: function(output_string){
                    PictureNumber = output_string['picturenumber'];
                    alert(PictureNumber);
                }
              });
              var currentVote = parseInt($("#" + picNum).attr("value"));  
              alert("pictureNumber is " + pictureNumber + "and currentVote is " + currentVote); //here to help me, no functionality
              $newVote = currentVote + 1;
              alert($newVote); //here to help me
          }
   </script>
/

upload/pics/changeVote.php

<?php
   $picNum = $_POST['picNum'];
function otherFileFunc($pic){
  $final = $pic + 1;
  return $final;
}
$outputnumber = function($picNum);
$array = ('picturenumber' => $outputnumber);
echo json_encode($array);
?>

/upload/pics/changeVote 中的错误.php

$outputnumber = function($picNum);

必须是:

$outputnumber = otherFileFunc($picNum);

不能使用 function() ,应改用函数名。