Created
July 28, 2011 17:25
-
-
Save irae/1112037 to your computer and use it in GitHub Desktop.
Recursivelly call the same ajax until certain return.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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