CORS
全称:Cross-Origin Resource Sharing
在ST的 文档中是这么写的
A relatively new capability of modern browsers is called CORS, which stands for Cross-Origin Resource Sharing. This allows you to send requests to other domains without the usual security restrictions enforced by the browser. Sencha Touch 2 has support for CORS, though you'll probably need to do a little setup on your web server to enable it. If you're not familiar with what you need to do on your web server to enable CORS, a quick google search should give you plenty of answers.
Assuming your server is set up though, sending a CORS request is easy:
Ext.Ajax.request({
url: 'http://www.somedomain.com/some/awesome/url.php',
withCredentials: true,
useDefaultXhrHeader: false
});
Form Uploads
The final thing we'll cover is uploading forms. This is also really easy:
Ext.Ajax.request({
url: 'myUrl',
form: 'myFormId',
callback: function(options, success, response) {
if (success) {
Ext.Msg.alert('Success', 'We got your form submission');
} else {
Ext.Msg.alert('Fail', 'Hmm, that did not work');
}
}
});
This finds a <form> tag on the page with id="myFormId", grabs its data and puts it into the request params object just like at the start of this guide. Then it submits it to the url you specified and calls your callbacks like normal.
查了一下相关资料 确实是可以实现的
服务器端对于CORS的支持,主要就是通过设置Access-Control-Allow-Origin来进行的。如果浏览器检测到相应的设置,就可以允许Ajax进行跨域的访问。
Apache:Apache需要使用mod_headers模块来激活HTTP头的设置,它默认是激活的。你只需要在Apache配置文件的<Directory>, <Location>, <Files>或<VirtualHost>的配置里加入以下内容即可:
Header set Access-Control-Allow-Origin *
public void doOptions(Representation entity) {
Form responseHeaders = (Form) getResponse().getAttributes().get("org.restlet.http.headers");
if (responseHeaders == null) {
responseHeaders = new Form();
getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
}
responseHeaders.add("Access-Control-Allow-Origin", "*");
responseHeaders.add("Access-Control-Allow-Methods", "POST,OPTIONS");
responseHeaders.add("Access-Control-Allow-Headers", "Content-Type");
responseHeaders.add("Access-Control-Allow-Credentials", "false");
responseHeaders.add("Access-Control-Max-Age", "60");
}
PHP:只需要使用如下的代码设置即可。
<?php
header("Access-Control-Allow-Origin:*");
也可以这样 指定你的域名
Access-Control-Allow-Origin: http://www.somedomain.com
浏览器支持情况
参考 http://blog.csdn.net/hfahe/article/details/7730944
- 大小: 31.5 KB
分享到:
相关推荐
sencha touch ajax 帮助文档 Sencha2 提供了若干种方便的方式,可以帮助你的应用实现数据的加载和输出。所有的数据捆绑组件,比 如:Lists,Nested Lists 和使用Store 的DataViews,这些都可以从多种数据来源中读取或...
sencha touch2移动开发框架,ajax获取数据
本文通过对 Sencha Touch 框架的介绍,使读者对该框架有一定的了解,并通过一些代码示例给用户更详细直观的对 Sencha Touch 框架功能的了解。 ExtJS ExtJS 是为 web 开发人员提供的基于 JavaScript 和 web 标准快速...
Sencha Touch开发的项目《般若人生》源码
SenchaTouch通过使用Ext.Ajax.request请求C#的ashx后台处理文件,获取返回数据(附代码),以及senchatouch的AJAX框架和MVC框架的简介
sencha touch 应用案例 sencha touch 案例 一个完整的sencha touch 应用案例 移动WEB社区开发的日志案例 非常不错!
sencha touch 折叠list
MAC OS 下sencha touch +cordova 开发环境配置。可以将H5 hybird 应用打包成IOS 应用。
sencha touch 2.4.0最新版 原版包下载
sencha touch中文翻译文档,包含sencha touch入门基础和一些控件的使用说明
sencha touch cookbook 英文高清文字版 !
Sencha Touch 2入门教程之MVC 讲解如何使用 Sencha Touch 2 mvc模式来开发一个登录界面
sencha touch list demo
sencha touch动态加载组件及容器内容,防止加载时间过长的问题
讲其解压到Tomcat的webAPP目录下,即可访问
sencha touch 是一个移动平台UI开发框架,可以实现各种绚丽的页面效果
这是我做的一个sencha touch 的项目,测试并能运行,希望对大家有帮助
sencha touch grid