cross origin request in web application(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();
推荐答案
任何在外部访问的资源都应该声明(见访问外部网络资源):
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 应用程序中的跨源请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Web 应用程序中的跨源请求
基础教程推荐
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
- 每次设置弹出窗口的焦点 2022-01-01
- WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
- 什么是不使用 jQuery 的经验技术原因? 2022-01-01
- 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
- Node.js 有没有好的索引/搜索引擎? 2022-01-01
- jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
- 如何在特定日期之前获取消息? 2022-01-01
- 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
- 如何使用 CSS 显示和隐藏 div? 2022-01-01
