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

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

问题描述

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

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

主线程上的同步 XMLHttpRequest 已被弃用,因为它会对最终用户的体验产生不利影响.

由于我不知道是什么导致了它,我不知道要分享什么代码?当我导航到一个状态 (ui-router) 但没有与此状态关联的控制器时,就会出现问题.

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天全站免登陆