gpt4 book ai didi

javascript - Web 应用程序中的跨源请求

转载 作者:行者123 更新时间:2023-11-30 08:54:13 25 4
gpt4 key购买 nike

在我的 Tizen 系统应用程序中,我发出跨源 AJAX 请求,它在 Tizen 的浏览器中运行良好,但是当我将其打包为 Web 应用程序时,跨源请求无法运行。我已经在模拟器和真实设备上测试过它。我也是用webkit inspector记录网络日志,截图如下: enter image description here

有高手能告诉我为什么吗?

下面是我的代码:

var url = "";//this is assigned a domain which supports cross domain access according to HTML5 specification.
var client = new XMLHttpRequest();
client.open("GET", url, true);
client.setRequestHeader("Accept-Language", 'en-us');
client.onreadystatechange = function() { alert("succeed"); }
client.send();

最佳答案

任何从外部访问的资源都应该声明为(see Accessing External Network Resources):

You cannot access external network resources by default (WARP: W3C Access Requests Policy). So, you must request permissions for the widget to retrieve network resources. You can enter several URLs by using the Add button on the Access tab. For each URL, you can indicate if you want to allow the widget to access the URL sub-domains. The Allow subdomain column contents can be toggled by mouse clicks.

因此,如果无法访问我们在 config.xml 中定义的案例中所需的特定资源,它就无法工作:

<access origin="http://url_resource" subdomains="true"/>

<access origin="*" subdomains="true"/>

让一切过去。

关于javascript - Web 应用程序中的跨源请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15105698/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com