response({
"files": [
{
"type": "js",
"name": "script"
},
{
"type": "html",
"name": "file"
}
]
});
// ...
function ajax(url, callback, parse) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onload = function(){
if (this.readyState == 4) {
if (xhr.status >= 200 && xhr.status < 400) {
callback(the parse ? JSON.parse(xhr.responseText) : xhr.responseText);
}
}
};
xhr.send(null);
}
ajax(jsonp_url, function(data) {
data.files.forEach(function(item, i){
alert(data.item.type);
});
});
// ...
{
"files": [
{
"type": "js",
"name": "script"
},
{
"type": "html",
"name": "file"
}
]
}
Find more questions by tags JavaScriptJSONAJAXWeb Development
Will add a few thoughts: there are so many "alternatives" jquery with support for IE9 and above weight ~1-20KB (jq weighs ~80-120), also has ECMAScript 5 (for which I believe "now" is the time)... I Think every time to drag the library, which sometimes weighs more than website, simply unnecessary, especially when normally used only ~50% of its functionality. No doubt, the giants, squeezing out from the library, all of its potential, justify this weight. But simple sites with a minimum of images (and not only) who need often is just manipulation with the DOM (and other stuff) are just wasting traffic.
So, a slice of perfectionism (or stupidity - as), not more. - Rick_Pfannersti commented on July 8th 19 at 12:18