1
Is there any way to create a counter type with Ajax?
I have the code below, that when we perform a Submit in a form, it calls this ajax, and executes the predefined processes.
I wonder if after 3 events (clicks) the ajax direct the user to another page.
jquery:
jQuery(document).ready(function(){
jQuery('#addpayment').submit(function(){
var dados = jQuery( this ).serialize();
jQuery.ajax({
type: "POST",
url: "redir.php",
data: dados,
success: function envio()
{
var cont = "Pagamento realizado.";
document.getElementById("sucesso").style.color="#FF0000";
document.getElementById("sucesso").innerHTML = cont ;
setTimeout(function() {
document.getElementById("sucesso").style.display="none";},3000);
document.getElementById("sucesso").style.display="inline"
}
});
return false;
});
});
html:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="#" method="post" id="addpayment" name="addpayment" class="form-horizontal">
<fieldset>
<!-- Button -->
<div class="form-group" align="center" >
<label class="col-md-4 control-label" for="singlebutton"></label>
<div class="col-md-4">
<input type="submit" name="submit" id="submit" class="btn btn-success" value="Enviar" >
</form>
<div id=sucesso></div>
</div>
</div>
</fieldset>
You want that when the user clicks 3 times on the "Send" button, it is redirected to another page?
– Valdeir Psr
Wow, make a normal variable and increment it with each click. When you have 3 redirects the guy with window.href.
– Francisco
@valdeir, yes exactly.
– user54154
@Francisco, my difficulty is this. Generate a counter (variable and increase). I do not know much the syntax of Ajax.
– user54154