Jquery ajax success callback function to implement the button ash countdown

  • 2020-03-29 23:50:17
  • OfStack

After the successful sending of SMS message by asynchronous mobile phone, the sending button is set to dust and counted down in the ajax success callback. At the beginning, js error has been reported all the time. The problem may be that this is updated after calling ajax

Button countdown code
 
var wait = 60; 
get_code_time = function (o) { 
if (wait == 0) { 
o.removeAttribute("disabled"); 
o.value = " Free access to captcha "; 
wait = 60; 
} else { 
o.setAttribute("disabled", true); 
o.value = "(" + wait + ") Second to retrieve "; 
wait--; 
setTimeout(function() { 
get_code_time(o) 
}, 1000) 
} 
} 

Call the get_code_time function code after getting the SMS
 
//Retrieve the captcha
$('#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(" SMS verification code sending failed "); 
} 
} 
}, 
error: function (data) { 
if(data.status == 0) { 
alert(data.msg); 
} else { 
alert(" SMS verification code sending failed "); 
} 
} 
}); 
}); 

Related articles: