如何在Chrome应用中执行同步XMLHttpRequest? [英] How to do a synchronous XMLHttpRequest in Chrome App?

查看:302
本文介绍了如何在Chrome应用中执行同步XMLHttpRequest?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下代码:

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

产生以下错误:

未捕获的InvalidAccessError:无法在"XMLHttpRequest"上执行打开":此页面已禁用同步请求.

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?

推荐答案

Chrome应用默认情况下禁用同步XMLHttpRequests.

Synchronous XMLHttpRequests are disabled by default for Chrome apps.

选中此链接,以查看所有禁用的Web功能和解决方法.对于这种情况:

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

使用仅异步XMLHttpRequest:摆脱同步XXR.

这篇关于如何在Chrome应用中执行同步XMLHttpRequest?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆