Ram Narayanan Ram Narayanan - 4 months ago 24x
PHP Question

500 Internal Server Error due to JQuery Ajax Post

Found the answer:

The error was the semicolon and it worked ! But as "KIKO Software pointed out" due the code that didn't make sense the data was added twice in the database hence I removed the "$("script").html(result);" line in the html file and everything worked like a charm. And this was nothing related to server error 500.... Just a few errors in the code.

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.

The Ajax call in add_pet.html

function add_trigger(){
var name=$('#name').text();
var breed=$('#breed').text();
type: "POST",
url: "add_pet.php",
data: "PET_NAME="+name+"&PET_BREED="+breed,
cache: false,
success: function(result) {
$('div[contenteditable]').keydown(function(e) {
if (e.keyCode === 13) {
return false;

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

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


$count_results=execute_MYSQL("SELECT * FROM PETS;");
echo "<script>alert('line=INSERT INTO PETS VALUES ($PET_ID,\"$PET_NAME\",\"$PET_BREED\",$doctorid'));</script>";
echo "<script>window.location.href='view.html'</script>"

Screen shot of the error

enter image description here


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


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.