【发布时间】:2012-05-12 21:55:44
【问题描述】:
我是网络编程新手,所以请原谅我的幼稚问题,我尝试在网络上搜索但找不到我基本问题的答案。
我在服务器端使用 extjs(用于小部件和 ajax)和 python(使用瓶子)。
这是我的要求。
我有 extjs EditorGrid,它只有一列(可编辑)。在索引路由(瓶子路由)上,我返回填充在此网格中并显示的 json 字典,到目前为止一切正常,现在我想更新此列的值并将更新后的值保存在服务器端。
所以我在我的 python 脚本上添加了另一条路由,并将 ajax_reply 作为我在 javascript 上的 ajax 请求的 URL(代码如下)。
现在我的问题是我如何向客户端发送响应,例如我想向客户端发送失败消息(即更新在服务器上不成功,我想发送更新失败的 ajax 响应。我尝试发送我的 ajax_reply 路由中的随机内容,但总是在客户端调用成功。
我很困惑如何从 ajax_repose 函数发送一个 json 响应,然后在我的 javascript 成功或失败函数中再次解析它以采取相应的行动。
非常感谢任何帮助
@bottle.route('/ajax_reply', method='POST')
def update_column():
return { 'success' : False }
var grid = new Ext.grid.EditorGridPanel({
tbar: [{ text : 'Remove' }, {text : 'Add'}],
ds: ds,
frame:true,
listeners: {
afteredit : function(e){
Ext.Ajax.request({
url : '/ajax_reply',
params : {
action: 'update',
id : e.record.id,
field: e.field,
value : e.value
},
success : function(resp, opt){
e.record.commit();
Ext.Msg.alert('SUCCESS', 'success...');
},
failure: function(resp, opt){
Ext.Msg.alert('ERROR', 'error...');
e.record.reject();
}
});
}
},
【问题讨论】:
标签: javascript python ajax extjs bottle