How to do a synchronous XMLHttpRequest in Chrome A

2019-07-23 04:38发布

问题:

Using the following code:

var xhr = new XMLHttpRequest();
xhr.open('GET', url, false);

Yields the following error:

Uncaught InvalidAccessError: Failed to execute 'open' on 'XMLHttpRequest': Synchronous requests are disabled for this page.

Is it simply not possible, or am I doing it wrong? Do I need extra permissions?

回答1:

Synchronous XMLHttpRequests are disabled by default for Chrome apps.

Check this link to see all disabled web features and the workarounds. For this case:

Use async-only XMLHttpRequest: Getting Rid of Synchrounous XXRs.