Last active
December 19, 2015 04:09
-
-
Save calvinmetcalf/5895562 to your computer and use it in GitHub Desktop.
pedantically similar typical (bad) ajax worker
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
function paralellAjax(url,callback){ | |
var quickAjax = function(url,cb){ | |
var ajax = new XMLHttpRequest(); | |
ajax.onreadystatechange = function(resp){ | |
if(ajax.readyState === 4 && ajax.status === 200) { | |
cb(JSON.stringify(ajax.response)); | |
} | |
} | |
ajax.open('GET',url,true); | |
ajax.send(); | |
} | |
var ajaxWorker = cw(quickAjax) | |
ajaxWorker.data(url).then(function(data){ | |
callback(null,data); | |
ajaxWorker.close(); | |
},function(data){ | |
callback(data); | |
ajaxWorker.close(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment