2012-05-29 2 views
0

상태 및 댓글을 업데이트 할 사이트가 있습니다 데이터베이스에서 내 상태 및 댓글 쿼리를 모두 나열해야합니다. 상태를 주석으로 사용하기 전에 업데이트 버튼을 삽입해야 업데이트 할 수 있습니다. 버튼이 작동하지 않습니다. 내 코드 먼저 반환 내가 업데이트 상태 및 업데이트 코멘트를 처리하는 스크립트가요소 (버튼)가 작동하지 않는 AJAX 응답을 받았습니까?

recevie에서
  echo ' 
    <div class="stbody"> 
     <div class="stimg"> 
      <img width="40" height="40" src="/images/uploads/.' . $json_data["picture"] .'"> 
     </div> 
     <div class="sttext">' . 
     " AAAAAAA" . 
     '</div> 
     <a href="#" class="delete" style="display: none; "> Remove</a> 

     <a href="#"id ="comment_link">Comment</a> 
     <span class="icodot"> 5 comment</span> 
     <span class="likelink"><a href="" isliked="0">Like</a> 10 liked</span> 
     <div id="box_comment" class="bxcomment"> 
      <form> 
       <div id="status' . $model->status_id . '" class="rowcomment" > 
        <div class="rowcommentlt"> 
         <a> 
          <img width="40" height="40" src="http://3.1.s50.avatar.zdn.vn/avatar_files/3/c/d/8/giaosudau_50_3.jpg"> 
         </a>           
         <textarea class ="text_area" id="txtComment' . $model->status_id . '"></textarea> 
         <br> 
        </div> 
        <div class="bxcmtend"> 
         <span class="tipcmtend">Nhấn Shift + Enter để xuống dòng</span> 
         <span class="btncmtend"> 
          <a class="comment_submit" href="#" 
          onclick="return false;" id="' . $model->status_id . '"><em>Comment</em></a>    
          <a onclick="return false;" rel="for_3073657831" id="emofeed_3073657831" class="emofeed" href="#" tabindex="0"></a> 
         </span> 
        </div> 
       </div> 
      </form> 

     </div> 
    </div> 

'; 

아약스 요청에 대한 문자열 처리되는 첫 번째

$(".comment_submit").click(function(){ 
    var element = $(this); 
    var status_id = element.attr("id"); 
    var comment = $("#txtComment"+status_id).val(); 
    var dataString = 'comment='+ comment + '&status_id=' + status_id; 
    if(comment=='') 
    { 
     alert("Please Enter Some Text"); 
    } 
    else 
    { 

     $("#flash"+status_id).show(); 
     $("#flash"+status_id).fadeIn(400).html('<img src="ajax-loader.gif" align="absmiddle"> loading.....'); 
     $.ajax({ 
      type: "POST", 
      url: "insertajax.php", 
      data: dataString, 
      cache: false, 
      success: function(html){ 
       $("#loadplace"+Id).append(html); 
       $("#flash"+Id).hide(); 
      } 
     }); 
    } 
    return false; 
}); 
,691 코멘트입니다 나는 HTML 코드가 정상 수신하지만 그것은 작동하지 않습니다 코멘트에서 클릭하면 363,210

두 번째는 핸들 업데이트 상태

success: function(data){ 

       $(data).prependTo(".timeline").slideDown("slow");         
       $(".loading").hide(); 
       $(".input_box").val("So what's on your mind?").css("color","#808080") 
       .css("height","30px"); 
      } 

입니다.

진심으로 감사드립니다. 어떻게해야합니까 클라이언트 json에 응답해야하고 클라이언트에서 html 코드를 삽입해야합니까?

+1

comment_submit (html a 요소)에는 인라인 이벤트 처리기 "onclick"이 있습니다. 이것은 jquery bound "click"보다 우선합니다. 깔끔한 것들을 인라인 onclick 처리기를 제거하고 알려지지 않은 문제를 제거하는 데 도움이됩니다. – Robbie

+0

제거하지만 작동하지 않습니다. – chanhle

+0

컨트롤러가 이것을 처리 할 수 ​​있습니까? –

답변

0

응답이 작동하지 않는다고 말하는가? IN

$("#loadplace"+Id).append(html); 
$("#flash"+Id).hide(); 

"ID"는 정의되지 않았습니다. 이는 응답이 결코 표시되지 않음을 의미합니다. 아마도 status_id를 의미할까요? 나는 내 문제를 가지고 사람을 요구했다

+0

하지만 텍스트 영역 경고에 문자를 입력하지 않으면 작동하지 않습니다 ("Please Please Some Text"); 여기에있는 이드는 내 문제가 아니다. 답해 주셔서 감사합니다. – chanhle

1

은 (CSTE 연구진 사용) 또는 내가 $(document).on('click', '.comment_submit', function(){

$(".comment_submit").click(function(){에서 변경이 경우) ( 를 살고 그것은 작동해야 모든 페이지에서 이벤트를 처리합니다. 모두들 감사합니다.

관련 문제