【发布时间】:2011-06-20 01:01:57
【问题描述】:
我试图阻止 ExtJS 和 Java 之间的通信我正在将请求从 ExtJS 发送到使用 netty 的 Java 服务器。如果有人可以向我发送一个示例,说明如何从 java 端格式化响应以及如何从 ExtJS 端读取响应数据,我会提前感谢。 这是我在 ExtJS 方面的来源
var store = new Ext.data.JsonStore({
autoload: true,
baseParams: {
conid : '6b09477f-aa04-4f5a-b969-05277d01f07e'
},
root: 'OpenCashTime',
proxy: new Ext.data.ScriptTagProxy({
url: 'http://localhost:8080/getOpenCash?'
}),
fields: [{name: 'Time', mapping: 'Time', type: 'int'}]
});
store.load();
store.on('load', function() {
alert(store.getTotalCount());
});
store.on('write', function() {
alert(store.getTotalCount());
});
store.on('loadexception', function() {
alert("AAAAAA");
});
store.on('metachange', function() {
//alert(store.getTotalCount());
});
store.on('update', function() {
//alert(store.getTotalCount());
});
store.on('save', function() {
//alert(store.getTotalCount());
});
store.on('datachanged', function() {
//alert(store.getTotalCount());
});
执行此代码并接收此响应时 {"OpenCashTime":[{"Time":1291623637000},{"Time":1294914317000}]} 尽管即使 firebug 看到它的 Json,我仍然收到 loadexception
【问题讨论】:
-
为什么选择 ScripTagProxy?你会从跨域源加载数据吗?
-
是的,现在我在 localhost 上进行测试,而且它不在 ExtJS 在 Apache Tomcat 服务器上运行的同一台服务器上,netty 部分在不同的端口上运行,因此它被视为跨域
-
好的。对于 ScriptTagProxy,您的响应必须如下所示:
callback({"OpenCashTime": [{"Time":1291623637000},{"Time":1294914317000}]})。 -
那我不应该加个回调函数名吗?
-
是的。实际上,您应该使用
callbackParam参数配置您的ScriptTagProxy,即The name of the parameter to pass to the server which tells the server the name of the callback function set up by the load call to process the returned data object. Defaults to "callback".虽然我似乎记得,callback是使用的默认值。