blob: 10e2840ea882dd2ae83f6c490690cc3056be6d96 [file] [log] [blame]
module.exports = function JSONLoader(){
var self = this;
function receivedResponse(xhr){
return xhr.status==200 && xhr.readyState==4;
}
function handleResponse(xhr,callback){
xhr.onreadystatechange = function(){
if ( receivedResponse(xhr) ){
try{
callback(null,JSON.parse(xhr.responseText) );
}catch(err){
callback(err,null);
}
}
}
}
self.load = function(location,callback){
var xhr = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
xhr.open("GET", location, true);
handleResponse(xhr,callback);
xhr.send();
};
};