3

我收到内部服务器错误,状态 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;

?>
4

2 回答 2

5

内部服务器错误是众多HTTP 状态代码之一,其来源在服务器端(最有可能是 PHP)。

检查您的网络服务器日志。您的 500 错误的根源在那里:)

于 2012-12-19T15:40:56.467 回答
3

您的 ajax 请求未发送此帖子变量:$_POST['panel_desc']

于 2012-12-19T15:39:37.690 回答