500内部服务器错误归因于JQuery Ajax Post [英] 500 Internal Server Error due to JQuery Ajax Post

查看:92
本文介绍了500内部服务器错误归因于JQuery Ajax Post的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

找到答案:

我在尝试执行AJAX发布时陷入困境.由于某种原因,我收到服务器500错误.我可以看到它在控制器中达到了断点.我尝试从PHP文件中发出警报和回声,但它不起作用.我尝试查看其他堆栈溢出查询,但没有帮助.

I am stuck while trying to perform an AJAX post. For some reason, I'm getting a server 500 error. I can see it hit break points in the controller. I tried alerting and echo from the PHP file, and it doesn't work. I tried looking at other stack overflow queries and it didn't help.

add_pet.html

<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>

add_pet.php 代码将数据插入数据库:

add_pet.php code to insert the data into the database:

<?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>"

错误的屏幕截图

推荐答案

内部服务器错误是由于服务器端脚本错误引起的.它与客户端脚本无关.因此,我想您应该检查php代码..您缺少

The Internal server error is caused due to the error in server side scripting. It hasn't everything to concern with the client side script. So I guess you should check the php code.. You are missing a

';'

在服务器端的最后一个回显中..您还应该提供完整的php代码,我的意思是服务器数据库连接和execute_MYSQL函数定义.错误也可能出在其中.

on last echo on server side.. and you should also give your full php code I mean the server database connection and the execute_MYSQL function definition. The error may also be in them.

这篇关于500内部服务器错误归因于JQuery Ajax Post的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆