2013-06-16 2 views
0

현재 내 localhost (xampp 1.8.1)에서 VirtualHosts (http://sub.local/ : c :/xampp/htdocs/cake/app/webroot를 가리키는 CakePHP 2.3.4를 실행 중입니다. /).CakePHP 2.3.4 : Ajax 요청시 내부 서버 오류가 발생했습니다.

AJAX를 사용하여 내 뉴스 페이지에 대한 주석 기능을 작성하여 주석을 추가하려고합니다. 여기

<textarea class="expanding" placeholder="Write your comment..." name="comment[<?php echo $news['News']['id']; ?>]"></textarea> 

아무것도 더 있지만, 뉴스 텍스트 자체와 페이지의 나머지 : 그래서 난 단지 주석을 입력 할 양식 필드로 텍스트 영역을 얻었다. 텍스트는 지금까지 작동중인 Enter 키를 눌러 제출됩니다. 가득 차있는 js 기능 :

$this->Js->buffer(' 
      $("textarea").keypress(function(e) { 
       if(e.which == 13) { 
        if ($(this).val() != "") { 
         // submit via ajax 
         var formData = $(this).serialize(); 

         ' . $this->Js->request(
           array(
            'controller' => 'comments', 
            'action' => 'add', 
            '1' 
           ), 
           array(
            'method' => 'POST', 
            'async' => true, 
            'type' => 'json', 
            'data' => 'Testing comment.', 
            'success' => ' 
               // delete textarea value 
               $(this).val(""); 

               // add to form 
               $("#c-comments").prepend("comment div following here"); 
              ', 
            'error' => ' 
               $("#c-errorBoxes").html(
               \' Your comment was not added. \' + textStatus + \' \' + errorThrown + \' </div>\' 
               ); 
              ' 
           ) 
          ) 
         . ' 
        } 

        e.preventDefault(); 
       } 
      }); 
'); 

두 부호는 나가 전망 파일에서 쓴 것이다. 덧글/추가/작업은 다음과 같습니다.

public function add() { 
     $id = 1; 
     $this->Comment->recursive = -1; 
     $comment = $this->Comment->findById($id); 
     return json_encode($comment); 
    } 

이것은 테스트 용일 뿐이므로 작동해야합니다. 하지만 그럼에도 불구하고 Firebug에서 500 내부 서버 오류가 발생하고 오류 상자가 페이지에 표시됩니다. 지금까지 나는 무엇을 해야할지 모르겠다. 나는 여기서 읽은 많은 것들을 시도했지만 아무도 도움이되지 못했습니다.

호출중인 아약스의 성공 기능조차도이 코드에서 작동하지 않기 때문에 전체 데이터베이스 추가 기능은 여기에 표시되지 않습니다.

<script type="text/javascript"> 
//<![CDATA[ 
$(document).ready(function() { 
      $("textarea").autoResize(); 
      $("a.comments").click(function() { 
       $(this).parent().parent().next("div.c-contentBodyBoxHide").slideToggle(); 
      }); 
      $("textarea").keypress(function(e) { 
       if(e.which == 13) { 
        if ($(this).val() != "") { 
         // submit via ajax 
         var formData = $(this).serialize(); 

         $.ajax({async:true, data:"Testing comment.", dataType:"json", error:function (XMLHttpRequest, textStatus, errorThrown) { 
               $("#c-errorBoxes").html(
               '<div class="c-box c-error">' + 
               ' <img src="/img/status/error_32.png" alt="" />' + 
               ' Your comment was not added. ' + textStatus + ' ' + errorThrown + ' </div>' 
               ); 
              }, success:function (data, textStatus) { 
               // delete textarea value 
               $(this).val(""); 

               // hide no comments if shown 
               $("#c-commentsNone").hide(); 

               // add to form 
               $("#c-comments").prepend("bla"); 

               // remove possible error message 
               $("#c-errorBoxes").html(""); 
              }, type:"POST", url:"\/comments\/add\/1"}); 
        } 

        e.preventDefault(); 
       } 
      }); 
     }); 
//]]> 
</script> 

나는 감사하고 좀 더 아이디어를 다음 HTML에서 자바 스크립트의 출력이 (내가 위에 삭제 조금 더 코드)입니다.

+0

'/ app/tmp/logs' 로그를 확인하십시오 – noslone

+0

디버그 레벨을 2로 설정하고 오류가 있는지 확인하십시오 – ammu

답변

2

/app/tmp/logs와 함께 힌트로 문제를 해결하면 오류 메시지가 나타납니다. 문제는 컨트롤러에서 add 액션이 add.ctp 뷰를 찾을 수 없다는 것입니다.

그냥 방법

$this->autoRender = false; 

를 추가 뷰를 렌더링에서 컨트롤러를 중지 할 (내가 시작을 선택) 더보기가 검색되지 않습니다. 요청이 지금 작동 중입니다!

도움 주셔서 감사합니다.

관련 문제