问题
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.
来源:https://stackoverflow.com/questions/27693814/how-to-do-a-synchronous-xmlhttprequest-in-chrome-app