Home  >  Article  >  Web Front-end  >  Implement button gray countdown in the success callback function of jquery ajax_jquery

Implement button gray countdown in the success callback function of jquery ajax_jquery

WBOY
WBOYOriginal
2016-05-16 17:13:581314browse

The main purpose is to realize that after the asynchronous mobile phone successfully sends a text message, the send button is grayed out and counts down in the success callback of ajax. At the beginning, a js error is reported all the time. The problem may be that this is updated after calling ajax. Feel free to change the this object before doing so. Assigning it to a variable is no problem

Button countdown code

Copy code The code is as follows:

var wait = 60;
get_code_time = function (o) {
if (wait == 0) {
o.removeAttribute("disabled");
o.value = " Get the verification code for free";
wait = 60;
} else {
o.setAttribute("disabled", true);
o.value = "(" wait ") and get it again after seconds ";
wait--;
setTimeout(function() {
get_code_time(o)
}, 1000)
}
}

get After the mobile phone text message, call the get_code_time function code
Copy the code The code is as follows:

//Re-obtain verification Code
$('#codeagain').click(function() {
var o = this;
$.ajax({
url:"Tea_sendCode.action?jsoncallback=?",
type: "post",
data: {accountId:accountId},
dataType: "json",
success: function (data) {
if(data.status == 1 && data.code == 200){
alert("Verification code has been sent to your mobile phone");
get_code_time(o);
} else {

if(data.msg != ""){
alert(data.msg);
} else {
alert("Failed to send SMS verification code");
}
}
},
error: function (data) {
if(data.status == 0) {
alert(data.msg);
} else {
alert("Failed to send SMS verification code" );
}
}
});
});
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn