http500:服務器內部錯誤案例詳解(服務器代碼語法錯誤或者邏輯錯誤)
一、總結
服務器內部錯誤可能是服務器中代碼運行的時候的語法錯誤或者邏輯錯誤
二、http500:服務器內部錯誤案例詳解
只是一段在thinkphp5.0(php框架)中用jquery中的ajax中的post方法操作的案例
控制器代碼:
1 //ajax評論點贊 2 public function commentLike(){ 3 $data=input('post.'); 4 $cid=$data['cid']; 5 $ans=db('comment')->where('cid',$cid)->setInc('click'); 6 if(!ans) $this->error('點贊失敗!!'); 7 $clike=db('comment')->field('clike')->find($cid); 8 dump($clike);die; 9 }
jquery代碼
<script > $(document).ready(function(){ $(".clike").click(function(){ // alert('點贊成功!'); $.post("{:url('engage/commentLike')}", { cid:$(this).attr('value') }, function(data,status){ alert("Data: " + data + "\nStatus: " + status); }); }); }); </script>
html代碼
<span class="clike" value="{$vo.cid}"><i class="iconfont"></i>{$vo.clike}</span><span>回復</span>
點點贊按鈕的時候發生http500:服務器內部錯誤

錯誤
jquery.min.js:4 POST http://www.drsong.com/index.php/student/engage/commentlike.html 500 (Internal Server Error)
三、問題解析
服務器內部錯誤,說明和頁面端應該關系不大
加檢驗代碼


這樣的代碼也會報同意的http500的服務器內部錯誤,而且dump($ans);換成dump($cid);就不報錯誤了。
從php角度來說,這個代碼是有錯的,dump $ans的時候ans是沒有值的,所以這里是有錯的
所以可以得到服務器內部錯誤可能是服務器中代碼運行的時候的語法錯誤或者邏輯錯誤
