我收到内部服务器错误,状态 500,我不知道如何排除故障。我为 ajax 调用添加了错误捕获,但并没有告诉我太多。如何添加代码以了解请求文件中发生的情况?我试过做,var_dump()
但什么也没发生。
$('#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>');
}
});
}
});
对 php 文件 createpanel.php 的 Ajax 调用:
<?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;
?>