我收到內部服務器錯誤,狀態爲500,我不知道如何解決問題。我已經爲ajax調用添加了錯誤捕獲,但沒有告訴我很多。如何添加代碼以瞭解請求文件內部發生了什麼?我曾嘗試做一個var_dump()
但沒有任何事情發生。向PHP發出AJAX請求時會導致500內部服務器錯誤的原因是什麼?
$('#createpanelbutton').live('click', function(){
var panelname = $('#panelname').val();
var user_cat = $('#user_cat').val();
//var whocan = $('#whocan').val();
var errors='';
if(panelname=='')
errors+='Please enter a Brag Book name.<br/>';
if(user_cat=='0')
errors+='Please select a category.<br/>';
if(errors!=''){
$('#panel_errors2').html('<span class="panel_brag_errors">'+errors+'</span>');
return false;
}else{
$('#createpanelbutton').val('Creating Brag Book...');
$.ajax({
async:false,
dataType:'json',
type: 'POST',
url:baseurl+'createpanel.php',
error:function(data,status,jqXHR){ alert("handshake didn't go through")},
data:'name='+encodeURIComponent(panelname)+'&category='+encodeURIComponent(user_cat)+'&collaborator='+encodeURIComponent('me'),
success:function(response){
if(response.status=='success')
location.href=response.url;
if(response.status=='failure')
$('#panel_errors2').html('<span class="panel_brag_errors">'+response.message+'</span>');
}
});
}
});
Ajax調用到PHP文件createpanel.php:
<?php
include_once('s_header2.php');
if($_POST){
if($_POST['name'] == ''){
$msg = "Please enter Brag Book name.";
$result = array("status"=>'failure', "message"=>$msg);
}elseif($_POST['category'] == ''){
$msg = "Please select category.";
$result = array("status"=>'failure', "message"=>$msg);
}else{
$db = Core::getInstance();
$dbUp = $db->dbh->prepare("SELECT id FROM ".USERS_PANEL." WHERE user_id = :uID and title = :tit");
$result = '2';
$dbUp->execute(array(':uID'=>$_SESSION['sesuid'],':tit'=>$_POST['name']));
$result = '3';
$numrows = $dbUp->rowCount();
$result = '4';
if($numrows == 0){
$result = '5';
$dbIn = $db->dbh->prepare("INSERT INTO ".USERS_PANEL." (`user_id`,`title`,`category_id`,`desc`,`type`,`friend_id`) VALUES (?, ?, ?, ?, ?, ?)");
$dbIn->execute(array($_SESSION['sesuid'],$_POST['name'],$_POST['category'],$_POST['panel_desc'],$_POST['collaborator'],$_POST['jj']));
$lid = $db->dbh->lastInsertId();
//header("Location: ".BASE_URL.addslashes($_POST['bname'])."-".$lid."/");
$panelurl=BASE_URL.$_POST['name']."-".$lid."/";
$result = array("status"=>'success', "url"=>$panelurl, "name"=>$_POST['name'], "id"=>$lid);
}else{
$result = array("status"=>'failure', "message"=>'You already have a Brag Book with that name.');
}
}
}
echo json_encode($result) ;die;
?>
只有*開始調試500錯誤的地方是Web服務器的錯誤日誌。 – DaveRandom
嘗試發佈你的服務器錯誤日誌,這可能會幫助你(和我們) – freedev
看到你的調試轉儲直接導航到createpanel.php – jantimon