找到了答案:
我在尝试执行AJAX发布时陷入困境。由于某种原因,我收到服务器500错误。我可以看到它在控制器中达到了断点。我尝试从PHP文件中发出警报和回声,但它不起作用。我尝试查看其他堆栈溢出查询,但没有帮助。
add_pet.html中的Ajax调用
<script>
function add_trigger(){
var name=$('#name').text();
var breed=$('#breed').text();
$.ajax({
type: "POST",
url: "add_pet.php",
data: "PET_NAME="+name+"&PET_BREED="+breed,
cache: false,
success: function(result) {
$("script").html(result);
window.location.href='view.html';
}
});
}
$('div[contenteditable]').keydown(function(e) {
if (e.keyCode === 13) {
add_trigger();
return false;
}
});
</script>
<form>
<div id="Heading" style="font-weight:400">Join</div>
<div id='name_label' style="font-weight:100">Name:</div>
<div id='name' contenteditable='true' style="font-weight:100"></div>
<div id='breed_label' style="font-weight:100">Breed:</div>
<div id='breed' contenteditable='true' style="font-weight:100"></div>
<div id='add_trigger' onclick='add_trigger()' style="font-weight:400"><span style="cursor:pointer">Add pet</span></div>
</form>
Run Code Online (Sandbox Code Playgroud)
使用add_pet.php代码将数据插入数据库:
<?php
session_start();
$doctorid=$_SESSION['DOCTOR_ID'];
$PET_NAME=$_POST['PET_NAME'];
$PET_BREED=$_POST['PET_BREED'];
$count_results=execute_MYSQL("SELECT …Run Code Online (Sandbox Code Playgroud)