var ready = 1; while(ready){ajaxFunction()} ajaxFunction = function(){ ... success: function(){ ... ready = 0; } ... }