2014-03-06 2 views
0

MySQL 테이블에서 PHP 쿼리를 통해 생성 된 HTML 테이블이 있습니다.jquery.ajax로 특정 html 테이블 행 변경

<table> 
    <tr> 
     <th>Sl</th> 
     <th>ID</th> 
     <th>Article Name</th> 
     <th>Publish Status</th> 
    </tr> 
    <?php 
     $i = 1; 
     foreach ($obj->showAllFromTable('pattern') as $pattern) { 
     extract($pattern); 
     ?> 
    <tr> 
     <td><?php echo $i++; ?></td> 
     <td><?php echo $id; ?></td> 
     <td><?php echo $pattern_name; ?></td> 
     <td id="publish_<?php echo $id; ?>" class="status_pattern"> 
     <?php echo $publish; ?> 
     </td> 
    </tr> 
    <?php 
     }   
     ?> 
</table> 

해당 기사 행의 '게시'셀을 클릭하여 기사의 상태를 변경하고 싶습니다. 은 "성공"블록에서

<script type="text/javascript"> 
$(document).ready(function(){ 
$('.status_pattern').click(function(){ 
    var thisid = $(this).attr('id'); 

    $.ajax({ 
     url: "status_change_pattern.php", 
     data: { 
      id: thisid 
     }, 
     success: function (response) { 
      alert(response); 
     } 
    }); 
}); 
}); 
</script> 

, 나는의 텍스트를 변경하는 기능을 만들려는 대신에 "경고"로, 다음과 같이 나는이 목적을 위해 JQuery와의 아약스 방법을 사용하는 것을 시도하고있다 내가 클릭 한 특정 세포. "status_change_pattern.php"에는 "Hey Hey"라는 텍스트 만 있습니다. 아무도 도와 줄 수 있습니까? 부디. 감사합니다. . 당신은 쓸 필요가

+1

텍스트 대신'HTML을 시도()' – krishna

+0

은'status_change_pattern.php'의 코드가 무엇인가? –

+0

@SatishSharma : 그냥 "Hey Hey"라는 텍스트입니다. 나는 단지 "게시"셀의 텍스트를 "Hey Hey"로 변경하려고합니다. 내 문제는 텍스트를 변경하기 위해 특정 셀을 대상으로 할 수 없다는 것입니다. 나는 분명하다. – Placid

답변

0

ID를 보존하려면 closure을 사용해야합니다.

<script type="text/javascript"> 
$(document).ready(function(){ 
    $('.status_pattern').click(function(){ 
     var thisid = $(this).attr('id'); 

     $.ajax({ 
      url: "status_change_pattern.php", 
      data: { 
       id: thisid 
      }, 
      success: function (id) { 
       return function (response) { 
        $("#" + id).html(response); 
       } 
      }(thisid) 
     }); 
    }); 
}); 
</script> 
+0

나는 당신의 제안을 시도했다. 그러나 그것은 작동하지 않습니다. 코드에 문제가 있습니다. 마지막 (thisid) 이후. 이 코드를 사용하면 다른 jquery 코드도 작동을 멈 춥니 다. 제거; 다른 코드가 작동하도록 만듭니다. 그러나 유무에 관계없이; 주요 목적은 성취되지 않는다. – Placid

+0

OK';'을 제거했지만'id'를 알려주십시오. $ (id) 문 바로 위 – SajithNair

+0

예! 경고 ID가 ID를 표시하고 있습니다 !! !! 그러나 $ (id) .html (응답)이 작동하지 않습니다. – Placid

0

, 응답 여기

success: function (response) { 
      $(thisid).html(response); 
     } 

, 당신은 새로운 상태를 얻을 필요가있다.

+0

아니요, 작동하지 않습니다. 문제는 특정 셀을 대상으로 텍스트를 변경할 수있는 것 같습니다. – Placid

+0

당신은 'Hey Hey'라는 경고 (응답)를 받고 있습니까? –

+0

예 'Hey Hey'알림 (응답) – Placid

0

SajithNair가 제공 한 솔루션이 작동합니다. SajithNair에게 감사드립니다. 그러나 클로저를 사용하지 않고도이를 수행 할 수 있습니다. 아래 그림과 같이 :

$('.status_pattern').click(function() { 
     var thisid = $(this).attr('id'); 

     $.ajax({ 
      url : "status_change_pattern.php", 
      data : { 
       id : thisid 
      }, 
      success : function(response) { 
       $('#' + thisid).html(response); 
      } 
     }); 
    }); 

감사