图片是用js实现ajax的一个样例,可以看到用了很多判断去实现浏览器的兼容以及服务器
状态等,但是今天看JQuery实现ajax时,没有这些判断。我在网上看到JQuery实现的ajax
已经能够兼容浏览器了,所以我想问下这部分的内容在哪里优化的?
想问一下JQuery ajax如何解决浏览器的兼容性问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
6条回答 默认 最新
- Go 旅城通票 2017-07-26 08:11关注
你的这些代码jquery已经写到js文件里面了,自己看未压缩的jquery文件不就清楚了
https://code.jquery.com/jquery-1.12.4.js// Functions to create xhrs function createStandardXHR() { try { return new window.XMLHttpRequest(); } catch ( e ) {} } function createActiveXHR() { try { return new window.ActiveXObject( "Microsoft.XMLHTTP" ); } catch ( e ) {} } jQuery.ajaxSettings.xhr = window.ActiveXObject !== undefined ? // Support: IE6-IE8 function() { // XHR cannot access local files, always use ActiveX for that case if ( this.isLocal ) { return createActiveXHR(); } // Support: IE 9-11 // IE seems to error on cross-domain PATCH requests when ActiveX XHR // is used. In IE 9+ always use the native XHR. // Note: this condition won't catch Edge as it doesn't define // document.documentMode but it also doesn't support ActiveX so it won't // reach this code. if ( document.documentMode > 8 ) { return createStandardXHR(); } // Support: IE<9 // oldIE XHR does not support non-RFC2616 methods (#13240) // See http://msdn.microsoft.com/en-us/library/ie/ms536648(v=vs.85).aspx // and http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9 // Although this check for six methods instead of eight // since IE also does not support "trace" and "connect" return /^(get|post|head|put|delete|options)$/i.test( this.type ) && createStandardXHR() || createActiveXHR(); } : // For all other browsers, use the standard XMLHttpRequest object createStandardXHR;
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 素材场景中光线烘焙后灯光失效
- ¥15 请教一下各位,为什么我这个没有实现模拟点击
- ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
- ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
- ¥20 有关区间dp的问题求解
- ¥15 多电路系统共用电源的串扰问题
- ¥15 slam rangenet++配置
- ¥15 有没有研究水声通信方面的帮我改俩matlab代码
- ¥15 ubuntu子系统密码忘记
- ¥15 保护模式-系统加载-段寄存器