500内部服务器错误归因于JQuery Ajax Post

Ram*_*nan 6 html php ajax jquery

找到了答案:

错误是分号,并且有效!但是正如“ KIKO Software指出”那样,由于在数据库中两次添加了没有意义的代码,因此我删除了“ $(“ script”)。html(result);“ 在html文件中排成一行,所有内容都像一个超级按钮。而且这与服务器错误500无关。...代码中只有几个错误。

我在尝试执行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 * FROM PETS;");
$PET_ID=$count_results->num_rows;
echo "<script>alert('line=INSERT INTO PETS VALUES ($PET_ID,\"$PET_NAME\",\"$PET_BREED\",$doctorid'));</script>";
execute_MYSQL("INSERT INTO PETS VALUES ($PET_ID,'$PET_NAME','$PET_BREED',$doctorid);");
echo "<script>window.location.href='view.html'</script>"
Run Code Online (Sandbox Code Playgroud)

错误的屏幕截图

在此处输入图片说明