Reuse XMLHttpRequest object or create a new one?

前端 未结 5 1829
感动是毒
感动是毒 2020-12-03 09:48

I searched stackoverflow but got contradictory answers:

Why should I reuse XmlHttpRequest objects?

Ajax-intensive page: reuse the same XMLHttpRequest object

5条回答
  •  醉梦人生
    2020-12-03 10:31

    From MDN Web Docs:

    If the httpRequest variable is used globally, competing functions calling makeRequest() can overwrite each other, causing a race condition. Declaring the httpRequest variable local to a closure containing the AJAX functions avoids this.

    Source: https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX/Getting_Started

提交回复
热议问题