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>