Last active
September 14, 2016 12:42
-
-
Save englishextra/e2752e27761649479f044fd93a602312 to your computer and use it in GitHub Desktop.
Load .json file, but don't JSON.parse it
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
/*! | |
* Load .json file, but don't JSON.parse it | |
* modified JSON with JS.md | |
* gist.github.com/thiagodebastos/08ea551b97892d585f17 | |
* gist.github.com/englishextra/e2752e27761649479f044fd93a602312 | |
*/ | |
var AJAXloadUnparsedJSON = function (u, cb, e) { | |
var w = window, | |
x = w.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); | |
x.overrideMimeType("application/json;charset=utf-8"); | |
x.open("GET", u, !0); | |
x.onreadystatechange = function () { | |
if (x.status == "404") { | |
e && "function" === typeof e && e(); | |
console.log("Error XMLHttpRequest-ing file", x.status); | |
return !1; | |
} else if (x.readyState == 4 && x.status == 200 && x.responseText) { | |
cb && "function" === typeof cb && cb(x.responseText); | |
} | |
}; | |
x.send(null); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment