0

Zend Framework を使用しており、Zend_Db を使用してデータベースから行を取得しました。HTMLは以下の通りです。目的は、クリックしたときにスライドショー列の「はい/いいえ」テキストを切り替えることです。ajax 呼び出しが機能し、正しい結果が返されます。ただし、セルを選択してテキストを変更することはできませんでした。

<table class="table table-bordered table-striped">
            <thead>
            <tr>

                <th>ID</th>
                <th>title</th>
                <th>Caption</th>
                <th>Image</th>
                <th></th>
                <th></th>
                <th>Slideshow</th>
            </tr>
            </thead>
            <tbody>
                <?php
                foreach($this->sections as $section){
                    if($section['slide']==0){ $slideText='No';  }
                    if($section['slide']==1){ $slideText='Yes';  }
                    ?>
                <tr>

                    <td>
                        <span class="badge"><?php echo $section['id']; ?></span>
                    </td>
                    <td>
                        <?php echo $section['caption']; ?>
                    </td>
                    <td>
                        <?php echo $section['comment']; ?>
                    </td>
                    <td>
                        <img src="/images/uploads/<?php echo $section['image_url']; ?>" width="180" height="100">
                    </td>
                    <td><a href="<?php echo $this->url(array('id'=>$section['id'],'sid'=>$this->id, 'type'=>'edit'),'admin-edit')  ?>">Edit</a></td>
                    <td><a href="<?php echo $this->url(array('id'=>$section['id'],'sid'=>$this->id,'type'=>'delete'),'admin-edit')  ?>">Delete</a></td>
                    <td class="imgajax"><a href="<?php echo $this->url(array('id'=>$section['id'],'type'=>'update'),'ajax-admin',true,true)  ?>" class="slide"><?php echo $slideText; ?></a></td>
                </tr>
                    <?php }?>

            </tbody>
        </table>
        <?php } ?>

JavaScript は次のとおりです。

$(".imgajax a").click(function(event){
        event.preventDefault();
        var url = $(this).url();
        id = url.segment(4);

        $.ajax({
            type: 'GET',
            url:"/admin/ajax",
            data:"id="+id,
            success: function(data) {
                console.log(data);

                if(data==1){
                    $('.slide').text('Yes');
                }
                if(data==0)
                {
                    $('.slide').text('No');
                }
            }
        });

    });
4

1 に答える 1

0

使用する必要があります

$('.slide').html('Yes');

それ以外の

$('.slide').text('Yes');
于 2012-08-21T08:59:36.280 に答える