After the asynchronous mobile phone is successfully sent, the send button is dimmed and countdown is implemented in the ajax success callback. The specific implementation example is as follows, if you like it, you can study how to set the sending button to gray and countdown in the ajax success callback after the asynchronous mobile phone successfully sends text messages. At the beginning, JavaScript errors were reported, the problem may be that this is updated after ajax is called. If you want to assign this object to a variable before this, no problem occurs.
Button countdown code
The Code is as follows:
Var wait = 60;
Get_code_time = function (o ){
If (wait = 0 ){
O. removeAttribute ("disabled ");
O. value = "get verification code for free ";
Wait = 60;
} Else {
O. setAttribute ("disabled", true );
O. value = "(" + wait + ") seconds before obtaining ";
Wait --;
SetTimeout (function (){
Get_code_time (o)
}, 1000)
}
}
Call the get_code_time function code after obtaining the SMS.
The Code is as follows:
// Obtain the verification code again.
$ ('# 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 ("the 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 ");
}
}
});
});