Home > Article > Web Front-end > Solution to implement jQuery's $.getJSON using native JavaScript_jquery
Today I am writing a DEMO, which uses jQuery’s $.getJSON method. After writing it, I found that this is the only place in jQuery that is used in the entire DEMO, but it is not cost-effective to introduce a jQuery, so I implemented it myself. A simple version, which can basically meet the needs, is now shared:
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.charset = "UTF-8";
script .src = url;
return true;
},
getQueryString: function(url) {
var result = {}, queryString = (url && url.indexOf("?")!=-1 && url.split("?")[1]) || location.search.substring(1),
re = /([^&=] )= ([^&]*)/g, m;
while (m = re.exec(queryString)) {
result[decodeURIComponent(m[1])] = decodeURIComponent(m[2]);
}
}
}
};
Call DEMO as follows: