asked on
<script type = "text/javascript">
var counter = 5;
var Pull = function (c) {
var data = JSON.stringify({ count: c });
$.ajax({
type: "POST",
url: "Accepted.aspx/Receipt",
contentType: "application/json; charset=utf-8",
data: data,
dataType: "json",
success: PullSuccess,
error: OnError
});
}
function PullSuccess(response) {
$("#<%= lbl.ClientID %>").text(response.d);
};
function OnError(response) {
$("#<%= lbl.ClientID %>").text("Error occured");
};
function countdown() {
var interval = setInterval(function () {
counter--;
if (counter <= 0) {
clearInterval(interval);
$("#<%= lbl.ClientID %>").text("Done");
} else {
Pull(counter);
}
}, 1000);
}
countdown();
// Works fine:
// Pull(5);
</script>
[System.Web.Services.WebMethod]
public static int Receipt(int count)
{
return count;
}