你要记得,永远要愉快地多给别人,少从别人那里拿取。——高尔基
最近发现一个网站:youmightnotneedjquery
https://youmightnotneedjquery.com/
直译过来就是你可能并不需要jquery…可以看出是有点恶趣味哈哈
对应的github地址为:https://github.com/HubSpot/YouMightNotNeedjQuery
这个网站它介绍了很多种使用新版IE新特性代替jquery的方法:
例如使用jquery时发送get请求获取json格式的数据
$.getJSON('/my/url', function(data) { });
使用IE10+时,不用依赖jquery,直接写
var request = new XMLHttpRequest(); request.open('GET', '/my/url', true); request.onload = function() { if (this.status >= 200 && this.status < 400) { // Success! var data = JSON.parse(this.response); } else { // We reached our target server, but it returned an error } }; request.onerror = function() { // There was a connection error of some sort }; request.send();
即可完成ajax请求,不过同时,也让代码更加繁重了,对于低版本IE的ajax请求,可以使用我这篇博客中的样子实现
当然这只是其中一个例子,更多的还是看上方网站