Is there any way to create a counter type with Ajax?
I have the following code, which when we make a submit in a form, it calls this ajax, and executes the pre-defined processes.
I would like to know if after 3 events (clicks) 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><formaction="#" 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>