這是我的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 }}) <?phpif(isset($_POST["postID"])){ echo $_POST["postID"];} ?>我試圖在javascript中將變量記錄到控制臺,它似乎工作。當我試圖返回它時,狀態碼是200。
為什么PHP收不到AJAX發出的post請求
楊__羊羊
2022-10-21 14:37:17