From 0504bec81da3bb3b5c3e6a918ffa205849de72d5 Mon Sep 17 00:00:00 2001 From: Leo Franchi Date: Wed, 14 Sep 2011 22:28:46 -0400 Subject: [PATCH] Add a Tomahawk.asyncRequest for async calls, ALL RESOLVERS SHOULD USE THIS --- data/js/tomahawk.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/data/js/tomahawk.js b/data/js/tomahawk.js index c95562a5c..17cc645bc 100644 --- a/data/js/tomahawk.js +++ b/data/js/tomahawk.js @@ -184,6 +184,21 @@ Tomahawk.syncRequest = function(url) } }; +Tomahawk.asyncRequest = function(url, callback) +{ + var xmlHttpRequest = new XMLHttpRequest(); + xmlHttpRequest.open('GET', url, true); + xmlHttpRequest.onreadystatechange = function() { + if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200) { + callback.call(window, xmlHttpRequest); + } else if (xmlHttpRequest.readyState === 4) { + Tomahawk.log("Failed to do GET request: to: " + url); + Tomahawk.log("Status Code was: " + xmlHttpRequest.status); + } + } + xmlHttpRequest.send(null); +}; + /** * * Secure Hash Algorithm (SHA256)