javascript - change id and use ajax -


i'm trying change id of button , use ajax, doesn't work. can 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 when change id, because if use first id (button), there work

try

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

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

post - imageshack API cURL -

dataset - MPAndroidchart returning no chart Data available -