这是我的javascript代码,成功事件被执行。但是 post 数组在 php 文件中保持为空。
document.querySelector(".postButtons").addEventListener("click",(e)=>{
const postID = e.target.value;
if(e.target.id == "edit"){
//Send post request to edit the post
$.ajax({
type: 'POST',
url: '../edit.php',
data: {postID : postID},
contentType: 'application/json; charset=utf-8',
data: 'json',
cache: false,
success: function(response) {
window.location.href="../edit.php"
},
error: function(err){
console.log(err)
}
})
}else if(e.target.id == "del"){
//Send post request to delete the post
}
})
<?php
if(isset($_POST["postID"])){
echo $_POST["postID"];
}
?>
我试图在javascript中将变量记录到控制台,它似乎工作。当我试图返回它时,状态码是200。
杨__羊羊
回首忆惘然
随时随地看视频慕课网APP
相关分类