Is it possible to using ajax call in a loop?
Here I want, when I single click on button then the ajax call will called 10 times. below is my code. Don't know is it good practice or not.
But I need this type of solution. How can I do it? thank you.
HTML:
<button>Click</button>
AJAX :
$(document).ready(function(e) {
$('button').click(function(){
for(var i=1;i<=10;i++){ //is it possible ?
$.ajax({
type:'POST',
url : "a.php",
data:'a='+$('.div1').text(),
success: function(result){
$('.div1').html(result);
}
});
}
});
});
a.php :
<?php
if(!isset($_POST['a']) || $_POST['a'] == ""){
$a = 0;
}
else{
$a = $_POST['a'] + 1;
}
echo $a;
exit();
?>