简体   繁体   English

JavaScript / PHP函数不会发布到另一个页面

[英]JavaScript/PHP function will not post to another page

I'm using PHP, but I have some variables that I'd like to post to another page using JavaScript. 我正在使用PHP,但是我想使用JavaScript将一些变量发布到另一个页面。 However, I cannot get it to work. 但是,我无法使其正常工作。 The strange thing is that I use this exact same function on some other pages, so I can't figure out why it's doing this. 奇怪的是,我在其他页面上使用了完全相同的功能,所以我不知道为什么要这么做。

The function is simply an input button (linked to a person's name and ID). 该功能只是一个输入按钮(链接到一个人的姓名和ID)。 When the button is pressed, I'd like for the name and ID to be posted to another page. 按下按钮后,我希望将名称和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()
    }
  );
}

I know replyID and userName are being set correctly, because when I write the variables to the page, they display correctly. 我知道replyIDuserName的设置正确,因为当我将变量写入页面时,它们会正确显示。

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

I even created a new page just to make sure something on postprocessing.php wasn't throwing off the POST. 我什至创建了一个新页面,只是为了确保postprocessing.php上的postprocessing.php不会引发POST。

I made this page titled postprocessing2.php where this was the only thing on it (aside from including the config file and whatnot). 我制作了名为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')");
  }

Replace "replyID=" + replyID + "&username=" + userName + "&tableName=testTable&category=flagPost" 替换为"replyID=" + replyID + "&username=" + userName + "&tableName=testTable&category=flagPost"

with

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM