jquery ajax load recursive callback -
here's jquery function, i'm stuck in circular callback functions. i'm wondering how convert code call itself? or possible?
$('#content').load('myurl/items', function() { ... ... $(this).find('form').submit(function(e) { e.preventdefault(); $.ajax({ type: 'post', url: 'myurl/items', context: document.getelementbyid('content'), }).done(function() { $(this).load('/myurl/items', function(){}); // recursive }); } });
declare function:
function loaditems() { $('#content').load('myurl/items', function() { ... ... $(this).find('form').submit(function(e) { e.preventdefault(); $.ajax({ type: 'post', url: 'myurl/items', context: document.getelementbyid('content'), }).done(function() { loaditems(); // call function continue }); } }); } loaditems(); // call function start
of course, loop end if ajax call ever unsuccessful.