在向PHP发出AJAX请求时导致500内部服务器错误的原因是什么?

时间:2021-07-15 20:30:09

I am receiving an internal server error, status 500 and I don't know how to troubleshoot. I have added error catch for the ajax call but doesn't tell me much. How do I add code to understand what is going on inside the requesting file? I have tried doing a var_dump() but nothing happends.

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

Ajax call to to php file createpanel.php:

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;

?>

2 个解决方案

#1


3  

This post var isn't being sent by your ajax request: $_POST['panel_desc']

你的ajax请求没有发送这个post var:$ _POST ['panel_desc']

#2


5  

Internal server errors are one of the many HTTP Status Codes and the origin is on the server side (PHP most likely).

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

Check your webserver log. The origin of your 500 error is there :)

检查您的网络服务器日志。你的500错误的起源是:)

#1


3  

This post var isn't being sent by your ajax request: $_POST['panel_desc']

你的ajax请求没有发送这个post var:$ _POST ['panel_desc']

#2


5  

Internal server errors are one of the many HTTP Status Codes and the origin is on the server side (PHP most likely).

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

Check your webserver log. The origin of your 500 error is there :)

检查您的网络服务器日志。你的500错误的起源是:)