[color=darkred][/color]function updateButton(store){
// 获取store中的脏数据
var modified = store.modified.slice(0);
//var view = Ext.getCmp("egp").getView();
var jsonArray = [];
if (modified.length > 0)
{
Ext.each(modified, function(m)
{
jsonArray.push(m.data);
})
Ext.Ajax.request
({
url : 'updateUsers.action',
params :
{
data : Ext.util.JSON.encode(jsonArray)
},
method : 'post',
success : function(response)
{
store.reload();
if(response.success)
{
Ext.Msg.show
({
title : '系统提示',
msg : '保存成功',
width : 200,
multiline : false,
closable : false,
buttons : Ext.MessageBox.OK,
icon : Ext.MessageBox.INFO
});
}
else
{
Ext.Msg.show
({
title : '系统提示',
msg : '不能修改ID 或者 输入的位数太长 保存失败',
width : 200,
multiline : false,
closable : false,
buttons : Ext.MessageBox.OK,
icon : Ext.MessageBox.INFO
});
}
},
failure : function()
{
Ext.Msg.show
({
title : '系统提示',
msg : '保存失败',
width : 200,
multiline : false,
closable : false,
buttons : Ext.MessageBox.OK,
icon : Ext.MessageBox.INFO
});
}
});
}else
{
Ext.Msg.show
({
title : '系统提示',
msg : '您没有修改,不需要保存!',
width : 200,
multiline : false,
closable : false,
buttons : Ext.MessageBox.OK,
icon : Ext.MessageBox.INFO
});
}
};
不管保存是否成功 每次都执行 success里面的else里面的 返回来 true false 都有
怎么改才对啊 求高手指导
Map rm = new HashMap();
rm.put("flag", false);
rm.put("msg", "系统错误,请稍后重试!");
or
rm.put("flag", true);
rm.put("msg", "保存成功!");
JsonUtil.write(rm, response.getWriter());
/*****************华丽的分割线***********************/
public static void write(Object object, Writer writer) throws Exception {
//如果是JSONObject和JSONArray就直接输出
if (object instanceof JSONObject || object instanceof JSONArray) {
try {
writer.write(object.toString());
} catch (IOException e) {
e.printStackTrace();
throw new Exception(e);
}
}
else {
Object writeObj = null;
if (object instanceof Collection) {
writeObj = javaObject2JsonArray(object);
}
else {
writeObj = javaObject2JsonObject(object);
}
try {
writer.write(writeObj.toString());
} catch (IOException e) {
e.printStackTrace();
throw new Exception(e);
}
}
}
此处的 success、failure 只是表明代码成功执行。
保存是否成功这个属于系统的业务逻辑,需要在ACTION返回的json对象中添加标识flag,
保存成功 flag:true;保存失败 flag:false。通过这个标识来判断保存是否成功,以及后续的界面显示问题