jQuery ajax async: false causes a strange warning?

前端 未结 5 1141
一生所求
一生所求 2020-12-04 02:10

In my JS App, i have many Ajax calls with async: false. I am using latest Chrome browser and in my console below warning appears recently.

<
5条回答
  •  没有蜡笔的小新
    2020-12-04 02:29

    This message is telling you that async: false creates a bad user experience. This is because it locks up the browser for the duration of the ajax call. This is not a bug, but an advisory message explaining that you're doing something you should probably not be doing.

    I have rarely ever seen a legitimate need for async: false, but programming with async: true (to create a better user experience) requires writing code that works with async operations. It is something you have to learn how to do, but is very doable once learned.

    You cannot just simply take code written to run synchronously and change the flag to be async and expect that synchronous code to work. Instead, you have to change your code to process an asynchronous response and you often have to restructure some code that uses the response to be in the asynchronous response handler.

    If you want to understand how to start coding with asynchronous ajax, then I'd suggest you read this question and it's various answers: How do I return the response from an asynchronous call?

提交回复
热议问题