Web应用程序中的跨源请求 [英] cross origin request in web application

查看:114
本文介绍了Web应用程序中的跨源请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Tizen系统应用程序中,我提出了一个跨源AJAX请求,它在Tizen的浏览器中运行良好,但是当我将其打包为Web应用程序时,交叉源请求无法工作。我已经在模拟器和真实设备上测试了它。
我还使用webkit检查器记录网络日志,截图如下:

In my application for Tizen system, I make a cross origin AJAX request, it works well in Tizen's browser, but when I package it as web application, the cross origin request can't work. I've tested it both on emulator and real device. I also use the webkit inspector record the network log, the screenshot is as following:

有没有专家告诉我原因?

Could any expert tell me why?

以下是我的代码:

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();


推荐答案

任何在外面访问的资源都应声明为< a href =https://developer.tizen.org/dev-guide/web/2.3.0/org.tizen.mobile.web.appprogramming/html/app_dev_process/accessing_external_network_resources.htm =nofollow>(见访问外部网络资源):

Any resource that it is accessed outside should be declared(see Accessing External Network Resources):


默认情况下,您无法访问外部网络资源(WARP:W3C
访问请求政策)。因此,您必须请求
小部件的权限才能检索网络资源。您可以使用访问选项卡上的添加按钮按
输入多个URL。对于每个URL,如果要允许窗口小部件访问URL子域,则可以指示
。可以通过鼠标点击切换
允许子域列内容。

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 中定义的情况下需要:

so it cannot work without having access to the specific resource needed in our case defined in config.xml:

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

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

让一切都过去。

这篇关于Web应用程序中的跨源请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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