JavaScript/PHP函数不会发布到其他页面


JavaScript/PHP function will not post to another page

我使用的是PHP,但我有一些变量想用JavaScript发布到另一个页面。然而,我无法让它发挥作用。奇怪的是,我在其他页面上使用了完全相同的函数,所以我不明白它为什么这么做。

该功能只是一个输入按钮(链接到一个人的姓名和ID)。当按下按钮时,我希望将姓名和ID发布到另一个页面。

function flagPost(replyID, userName){
  if(!confirm("Flag Post?"))
    return false;
  $.post('postprocessing.php',"replyID=" + replyID + "&username=" +
    userName + "&tableName=testTable&category=flagPost",
    function(response){
      window.location.reload()
    }
  );
}

我知道replyIDuserName设置正确,因为当我将变量写入页面时,它们会正确显示。

function flagPost(replyID, userName){
  document.write(replyID + userName)

我甚至创建了一个新页面,只是为了确保postprocessing.php上的某些内容不会影响POST。

我制作了这个名为postprocessing2.php的页面,这是它上唯一的内容(除了包含配置文件和其他内容)。

$category = $_POST['category'];
  if($category == "flagPost"){
    $table = $_POST['tableName']; //just testing, I use escape strings in the "real" code
    $postID = $_POST['replyID'];
    $username = $_POST['username'];
    mysql_query("insert into flaggedPosts VALUES('','$postID','$table','$username')");
  }

更换"replyID=" + replyID + "&username=" + userName + "&tableName=testTable&category=flagPost"

带有

$.post(url,{ replyID: replyID, username: userName, tableName: "testTable", category: "flagPost"},function...