2012-12-19 72 views
3

我收到內部服務器錯誤,狀態爲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; 

?> 
+7

只有*開始調試500錯誤的地方是Web服務器的錯誤日誌。 – DaveRandom

+0

嘗試發佈你的服務器錯誤日誌,這可能會幫助你(和我們) – freedev

+0

看到你的調試轉儲直接導航到createpanel.php – jantimon

回答

3

這篇文章VAR沒有被你的Ajax請求發送:$_POST['panel_desc']

+0

它是'$ _Post ['panel_desc']'和'$ _POST ['jj']'。我將這兩個領域留給了面板的初始設置。看起來PDO不會在空字段或空字段上前進。謝謝! –

+0

查看帖子http://www.developersnote.com/2014/01/solved-jquery-ajax-500-internal-server.html [鏈接] – shamcs

5

內部服務器錯誤是許多之一HTTP Status Codes並且起源位於服務器端(最有可能是PHP)。

檢查您的網絡服務器日誌。 500錯誤的起源在那裏:)

相關問題