php - Changing specific html table row by jquery.ajax -


i have html table generated php querying mysql table.

<table>    <tr>       <th>sl</th>       <th>id</th>       <th>article name</th>       <th>publish status</th>    </tr>    <?php       $i = 1;       foreach ($obj->showallfromtable('pattern') $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> 

i want change status of article clicking on 'publish' cell of corresponding article row. trying use ajax method of jquery purpose shown in following:

<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> 

in "success" block, instead of "alert", want create functionality change text of specific cell clicked. "status_change_pattern.php" has text "hey hey". can help? please. thanks.

you have use closure preserve id.

<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> 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -