Created
November 26, 2012 09:24
-
-
Save gockxml/4147359 to your computer and use it in GitHub Desktop.
Revisions
-
gockxml created this gist
Nov 26, 2012 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ function bind_ajax_update(selector, until, interval, get_status, callback){ var filters = [] interval = interval || 5000 for (var i in until){ filters.push("[status=" + until[i] + "]") } var ajax_update = function(elem){ var $elem = $(elem) var url = $elem.attr("data-url") console.log("ajax update") $.ajax({ url : url, success : function(data){ var status = get_status ? get_status.call(null, data) : data var finished = until.indexOf(status) >= 0 callback = callback || $elem.html callback.call($elem, status, elem, finished, data) if (!finished){ setTimeout(function(){ ajax_update(elem) }, interval); } } }) } $(document).ready(function(){ //console.log($(selector).filter(filters.join(","))) $(selector).each(function(){ ajax_update(this) }) }) }