blob: 10e2840ea882dd2ae83f6c490690cc3056be6d96 [file] [log] [blame]
bigbiffd006b302015-03-06 18:36:03 -05001module.exports = function JSONLoader(){
2 var self = this;
3
4 function receivedResponse(xhr){
5 return xhr.status==200 && xhr.readyState==4;
6 }
7
8 function handleResponse(xhr,callback){
9 xhr.onreadystatechange = function(){
10 if ( receivedResponse(xhr) ){
11 try{
12 callback(null,JSON.parse(xhr.responseText) );
13 }catch(err){
14 callback(err,null);
15 }
16 }
17 }
18 }
19
20 self.load = function(location,callback){
21 var xhr = (window.XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
22 xhr.open("GET", location, true);
23 handleResponse(xhr,callback);
24 xhr.send();
25 };
26};