Countdown to implemented buttons in the success callback function of jqueryajax _ jquery-js tutorial

Source: Internet
Author: User
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 ");
}
}
});
});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.