Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental解决办法
来源:互联网 发布:动易cms后台登录密码 编辑:程序博客网 时间:2024/05/01 18:53
为了获取ajax请求的返回值后进行下一步操作,我经常会这么用:
$.ajax_getType = function(open_id){ var url = '/ad/ad/get-type?open_id=' + open_id; //定义全局变量 return_data = ''; $.ajax({ url: url, async: false, // 关键,同步和异步的参数,若无此参数则不等ajax执行完就继续往下执行 type: 'get', success: function (data) { console.log('success!'); return_data = data; } }); return return_data; };
由于一直使用火狐浏览器调试,没发现有什么问题,后来偶然发现,这样使用在谷歌浏览器是会报
Synchronous XMLHttpRequest on the main thread is deprecated
because of its detrimental effects to the end user’s experience. For
more help, check https://xhr.spec.whatwg.org/.
同步的ajax请求会造成整个页面阻塞,等待ajax请求返回,因此在主线程运行会导致用户体验问题,谷歌浏览器直接禁用同步ajax。
解决办法:
异步操作只能在回调中进行。
$.ajax_getType = function(open_id){ var url = '/ad/ad/get-type?open_id=' + open_id; $.ajax({ url: url, type: 'get', success: function (data) { console.log('success!'); //在这里直接处理数据,或者调用函数 $.prepareDare(data); } }); };
0 0
- Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental解决办法
- Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to th
- 提交页面出现提示:Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effe
- 解决办法:Synchronous XMLHttpRequest on the main thread is deprecated because of its
- 关于谷歌..Synchronous XMLHttpRequest on the main thread is deprecated because of its...
- (前端)警告:Synchronous XMLHttpRequest on the main thread is deprecated
- 关于chrome控制台警告:Synchronous XMLHttpRequest on the main thread终极解决办法
- 关于chrome控制台警告:Synchronous XMLHttpRequest on the main thread终极解决办法
- 关于chrome控制台警告:Synchronous XMLHttpRequest on the main thread终极解决办法
- 关于chrome控制台警告:Synchronous XMLHttpRequest on the main thread终极解决办法
- 关于chrome控制台警告:Synchronous XMLHttpRequest on the main thread终极解决办法
- 关于chrome控制台警告:Synchronous XMLHttpRequest on the main thread终极解决办法
- error:chrome控制台警告:Synchronous XMLHttpRequest on the main thread...
- The application may be doing too much work on its main thread.问题可能的解决办法
- relying on packaging to define the extension of the main artifact has been deprecated and is schedul
- jQuery has deprecated synchronous XMLHTTPRequest
- The behavior of the UICollectionViewFlowLayout is not defined because 解决办法!
- fortran Because of COMMON, the alignment of object is inconsistent with its type
- toj 4615 Tetrahedrons and Spheres
- 图片压缩问题
- EventBus源码阅读(3)-Subscribe
- 栈的链表实现
- 宏和内联函数的小结
- Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental解决办法
- [Unity基础]移动平台下的文件读写
- Ext JS 6 下载与设置
- JNI/NDK开发指南(一)—— JNI开发流程及HelloWorld
- apache 配置与使用
- bootstrap模态框垂直居中效果
- 设计模式之代理模式(Proxy)
- c#可以创建任意控件的拖动
- 基于邻接矩阵图的广度优先遍历