Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
691 views
in Technique[技术] by (71.8m points)

angularjs - Synchronous XMLHttpRequest on the main thread is deprecated error

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

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.

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.

Anyone seen this before?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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

async: false

as an argument to any of the jQuery ajax calls.

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

xmlhttp.open(...)

is set to false.


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.


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:

How to $http Synchronous call with AngularJS

How to create synchronous using $http in angular.js

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...