Skip to content

Instantly share code, notes, and snippets.

@irae
Created July 28, 2011 17:25
Show Gist options
  • Save irae/1112037 to your computer and use it in GitHub Desktop.
Save irae/1112037 to your computer and use it in GitHub Desktop.
Recursivelly call the same ajax until certain return.
// WARNING: This is an antipattern, just to explain for a friend of mine how this could work
// Don't do this is serious projects.
function calendarLoop() {
$.ajax({
url:'/calendario/adicionar',
dataType: 'json',
data: {}, // an object to be serialized or string in param format data1=foo&data2=bar
success: function(data) {
if(data.repeat) {
// data is {"repeat":true}
calendarLoop();
} else {
// data is {"repeat":false,"html":"<p>result</p>"}
endLoop(data);
}
}
})
}
function endLoop(data) {
$('#taegetDiv').html(data.html);
// many other possibilities
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment