主线程上的XMLHttpRequest同步已弃用错误 [英] Synchronous XMLHttpRequest on the main thread is deprecated error

查看:358
本文介绍了主线程上的XMLHttpRequest同步已弃用错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因,我的Angularjs应用出现以下错误:

For some reason I'm getting the following error in my Angularjs app:

不赞成在主线程上使用同步XMLHttpRequest,因为它会对最终用户的体验产生不利影响.

由于我不知道是什么原因,所以我不知道共享什么代码? 当我导航到一个状态(UI路由器)但没有与此状态相关联的控制器时,就会出现此问题.

As I haven't got a clue what's causing it I don't know what code to share? The issue arises when I navigate to a state (ui-router) but there is no controller associated with this state.

有人看过吗?

推荐答案

这是由于尝试从浏览器进行同步AJAX调用引起的.

This is caused by trying to do a synchronous AJAX call from the browser.

如果Ajax调用是通过jQuery完成的,则是在使用时引起的:

If the Ajax call is done via jQuery, then it is caused when using:

async: false

作为任何jQuery ajax调用的参数.

as an argument to any of the jQuery ajax calls.

如果是用本机XMLHttpRequest完成的,那么它是由于第三个参数:

If it's done with native XMLHttpRequest, then it is caused when the third argument to:

xmlhttp.open(...)

设置为false.

因此,问题的根源是从您的网页Javascript进行了ajax调用.您将必须检查Ajax调用的所有位置,并找到设置错误参数的位置,修复该参数,并(可能)重新处理响应处理以使用异步响应.

So, the source of the problem is an ajax call being made from your webpage Javascript. You will have to examine all places that Ajax calls are made and find one that is setting the wrong argument, fix the argument and (probably) rework the response handling to work with an async response.

以下是有关在Angular中进行同步ajax调用的一种方式的一些文章,因此它可能会让您了解要查找的内容:

Here's are some articles about one way that synchronous ajax calls are made in Angular so it may give you an idea what to look for:

如何使用AngularJS进行$ http同步调用

如何使用angular.js中的$ http创建同步

由于angular默认情况下仅执行异步操作,因此您似乎必须竭尽全力创建自己的服务.为此,您将使用本机XMLHttpRequest对象,因此您可能只需要编写XMLHttpRequest的代码,然后查看引用的位置,然后在该邻域中找到一个.open()调用即可.

Since angular only does async by default, it looks like you have to go out of your way to create your own service. To so that, you will be using native XMLHttpRequest objects so you can probably just great the code for XMLHttpRequest and see where that is referenced and then find a .open() call in that neighborhood.

这篇关于主线程上的XMLHttpRequest同步已弃用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆