weixin_33747129 2015-07-24 22:11 采纳率: 0%
浏览 23

用ajax改变值

I have button, and when I click on it it run ajax that should change "startRow" values', but it doesn't.

Why is that? Here is the code -

<div id="commentsBox">
<?PHP 
    $startRow = 0;
    print_comments ($_GET['page'], $_GET['ownerID'], $startRow)
?>
</div>
<button class="btn btn-primary" id="moreComments" startRow='0' pageName="userPage" refID="<?PHP echo $_GET['ownerID'] ?>">MORE</button>

AJAX:

$(function () {
    $("#moreComments").click(function () {
        var element = $(this);
        var startRow = element.attr("startRow");
        var pageName = element.attr("pageName");
        var refID = element.attr("refID");
        var info = 'startRow=' + startRow + '&pageName=' + pageName + '&refID=' + refID;
        $.ajax({
            type: "POST",
            url: "ajax/moreComments.php",
            data: info,
            success: function (data) {
                $('#commentsBox').append(data);
                startRow = startRow + 20;
                $("#moreComments startRow").val(startRow);
                //element.attr( 'startRow' , startRow);
            }
        });
        return false;
    });
});
  • 写回答

1条回答 默认 最新

  • weixin_33720956 2015-07-25 00:27
    关注

    You ajax call is ok. The problem is that you are using the jQuery selector wrong.

    Instead of this:

    $("#moreComments startRow").val(startRow);
    

    You should do this

    $("#moreComments").attr("startrow",startRow);
    

    In the first one, you are trying to access to a child of moreComments and startRow is just an attribute of moreComments.

    Hope it helps!

    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 如何将下列的“无限压缩存储器”设计出来
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口