Cordova 积垢及;JsonP/Sencha Touch 2
通过代理类型“jsonp”上传记录的正确方式是什么? 我正在尝试使用代理类型“jsonp”同步()存储,但收到错误消息 这就是模型:Cordova 积垢及;JsonP/Sencha Touch 2,cordova,proxy,touch,extjs,jsonp,Cordova,Proxy,Touch,Extjs,Jsonp,通过代理类型“jsonp”上传记录的正确方式是什么? 我正在尝试使用代理类型“jsonp”同步()存储,但收到错误消息 这就是模型: Ext.define("Sencha.model.User", { extend:"Ext.data.Model", //idProperty:"", config:{ fields:[ 'userID', 'userName', 'userEmai
Ext.define("Sencha.model.User", {
extend:"Ext.data.Model",
//idProperty:"",
config:{
fields:[
'userID',
'userName',
'userEmail'
],
proxy: {
type: 'jsonp',
create : 'http://domainname.com/users.php?action=insert',
read : 'http://domainname.com/users.php?action=fetchAll',
update : 'http://domainname.com/users.php?action=update',
destroy : 'http://domainname.com/users.php?action=delete'
},
callbackKey: 'callback',
reader: {
type: 'json',
rootProperty: 'Users',
successProperty: 'success',
messageProperty: 'message'
},
writer: {
type: 'json',
writeAllFields: false,
encode: true
}
}
}
});
商店:
Ext.define("Sencha.store.Users", {
extend:"Ext.data.Store",
config:{
model:"Sencha.model.User",
remoteFilter:false,
remoteSort:true,
autoLoad:true,
}
}
});
商店已更新:
Ext.getStore('Users').set('userName', 'Tom');
现在我想更新数据库中的记录:
Ext.getStore('Objects').sync();
但我得到了一个错误:
未捕获错误:[Error][Ext.data.proxy.Server#create]JsonP代理只能用于读取数据。
如何更新记录数据?通过代理将其上载到数据库?您在所有BRWSER中默认处理CORS(跨源资源共享)。这是受尊重的,并且所有web服务器默认设置为不允许CORS请求。有关CORS的详细信息
如果您是web开发人员,拥有web服务器,但需要从javascript访问一些外部公司API,最简单的方法是将服务器设置为web代理
(大师级的读者们,请随意在这里添加更多的服务器配置,因为我将其命名为wiki)
使用mod_proxy和mod_proxy_http的Appache
打开虚拟主机文件并添加这些行(首先启用mod proxy-foirst-进一步阅读)
Nginx
如果您在应用程序配置中使用NGIX,请添加以下行
location /proxy {
proxy_pass http://domainname.com/;
proxy_set_header X-Real-IP $remote_addr; <-- maybe good to set
}
在phonegap(Sencha Touch)中,针对ajax请求设置用户名和密码,如buffer.SlowBuffer()
您将需要第一个方法来打包auth头
function make_base_auth(user, password) {
var tok = user + ':' + pass;
var hash = Base64.encode(tok);
return "Basic " + hash;
}
然后在代理集标题中,如下所示
headers : { Authorization : make_base_auth("some_username", "some_password") } // I know this is readable by other by you get the point.
IIS 6
要启用CORS Microsoft IIS6,请执行以下步骤:
还考虑检查上面提到的关于如何设置代理的文档,然后修改Web.CONFIG文件并添加FLASH
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
谷歌应用引擎也能帮上忙
因为它是很长,以适应这个框,我将只提供一个链接到一个博客,所有都是正确的解释
…那么第二种方法呢
好吧,它涉及一些本地编码,至少你们需要phonegap插件phonegap代理,你们可以找到,但我会避免“本地”,因为phonegap的目的是让多平台应用程序使用单一代码…哦,若你们想做你们的“特殊”插件,写本地代码就是一个很好的例子
现在由您决定采用哪种方法;)恐怕这不是我的选择,因为应用程序不是通过web服务器提供的,而是通过打包的移动应用程序提供的。不过,+1因为如果您使用web服务器,这肯定很有帮助。您仍然有选择,请检查我的更新,因为我没有更新我不知道你在用phonegap
headers : { Authorization : make_base_auth("some_username", "some_password") } // I know this is readable by other by you get the point.
<configuration>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 200;
}
if ($request_method = 'POST') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}