weixin_33670786 2016-02-05 20:41 采纳率: 0%
浏览 22

更改id并使用ajax [关闭]

Closed. This question needs debugging details. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 4 years ago.

I'm trying to change id of this button and then use ajax, but doesn't work. Can anyone help me?

My HTML Code:

<form action="" method="POST" class="button">
    <input type="hidden" id="userid" value="<?=$_GET["userid"]?>" />
    <button id="button" class="btn btn-primary"> Wait </button>
</form>

My jQuery Code:

<script type="text/javascript">
jQuery(document).ready(function ($) {
    $('#button').countTo({
        interval: 1000, startNumber: 2, endNumber: 0, onLoop: function (self, current, loop) {
            $(self).text('Wait: ' + current);
         },
        onFinish: function (self, current, loop) {
            document.getElementById("button").innerHTML = "close";
            document.getElementById("button").id = "go";
        }
    });
});
</script>

My Ajax Code:

$(document).ready(function() {
    $('#go').click(function() {
        var userid    = $('#userid').val();
        var dataString = 'userid=' + userid;
        $.ajax({
            type: "POST",
            url: "ajax.php",
            data: dataString,
            dataType: "json",
            success: function(data) {
                var success = data['success'];
                if (success == false) {
                    console.log('false');
                }
                if (success == true) {
                    console.log('true');
                }
            },
            error: function(data) {
                console.log(data);
            }
        }); 
        return false;
    });
});

I think it's something when I change the id, because if I use the first id (button), there will work

</div>
  • 写回答

1条回答 默认 最新

  • weixin_33726943 2016-02-05 20:55
    关注

    Try

     $(document).on("click","#go",function(){})
    
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘