store.load({ params : { start : 0, limit : inputPageSize } , callback : function(r, option, success) { //if (success == false) { // Ext.MessageBox.alert('提示', '会话超时,请注销登录4,如注销登录失败重启tomcat'); //}
alert("call back start");
alert(r[0]);
alert ("msg is:"+r[0].get('msg');
if(r[0]){
msg = r[0].get('msg');
if(msg){
Ext.Msg.alert('提示',msg);
}
} } });})
如何获得 r里的值那,比如返回的json值是:{"totalProperty":1,"root":[{"NODEDC":"HL","ISMONITOR":"0","MEMO":"test"}]}
前台接收的是后台传来的json串 在catch里面一样 也返回一段json串 而这个json串里面装的是错误异常信息
try{
out.println({root:[{name:value,,,,,},{name:value,,,,,}]});
}catch(Exception ex){
out.println({root:[{msg:'sfsdfdsf'}]}
}
把异常反映该前台 是没有问题的
r返回的是加载的record
callback : Function
在Record加载之后被调用的函数。 回调函数在load事件被触发后调用, 并且将会被传递如下参数:
r : Ext.data.Record[] 所加载的Record数组。
options : 调用load方法时的配置对象。
success : 布尔值,加载是否成功标识位。
后台返回的json值是:{"totalProperty":1,"root":[{"NODEDC":"HL","ISMONITOR":"0","MEMO":"test"}]}
那么r代表的就是root属性内里面的对象数组
通过r参数可以取到的值 只能是{"NODEDC":"HL","ISMONITOR":"0","MEMO":"test"}这里面的属性值
楼主你好,你只能取到返回记录里面的信息
额外的信息应该是取不到的
{success:false,msg:'A communication error has been detected. Communication protocol being used: Reply.fill(). Communication API being used: InputStream.read(). Location where the error was detected: insufficient data. Communication function detecting the error: *. Protocol specific error codes(s) TCP/IP SOCKETS DB2ConnectionCorrelator: GA194D45.BD3B.110513024207',check:false}
这段信息 你可以把他同样放到record的最后一条记录内
当success==false的时候 从record的最后一条记录中去取错误信息
这样处理的话 就需要你在后台对json重新组装一下
把错误信息添加到最后一条记录 默认记录为空 出现异常的时候 为最后一条记录赋值
不知道能否明白我的意思
正常情况
[{name:value,name:value}。。。。。,{msg:}]
出现异常的时候
可以把记录放到最后一条 或者干脆不要前面的记录 只是返回错误信息
[{msg:''}]
取记录的时候 使用r[0].msg
没有哪个参数可以获取到你的msg值,这种情况你只能修改你后台的json格式,如果出错则是查询不到结果,查询不到结果那你的结果集,也就是root中的内容就没有实际意义,你封装成这样
{"totalProperty":1,"root":[{"msg":"错误提示"}]}
然后你用r[0].msg获取你的错误提示信息
前台有异常吗
你在火狐控制台下 看一下响应的json串 是否和你后台传来的一致 如果一致 说明是前台处理有问题 多试一试 :D
楼主不要监听 store里的事件,
要监听store里定义的proxy事件
比如这个Ext.data.DataProxy里面的load事件(o值就是返回的response了),
[code="java"]load : ( DataProxy this, Object o, Object options )
Fires before the load method's callback is called.
Listeners will be called with the following arguments:
this : DataProxy
The proxy for the request
o : Object
The request transaction object
options : Object
The callback's options property as passed to the request function
DataProxy
loadexception : ( misc misc )
This event is deprecated. The signature of the loadexception event varies depending on the proxy, use the catch-all exception event instead. This event will fire in addition to the exception event.
Listeners will be called with the following arguments:
misc : misc
See exception.[/code]
[size=xx-large]{"totalProperty":1,"root":[{"NODEDC":"HL","ISMONITOR":"0","MEMO":"test"}]}
获取方法:
r.nodedc
r.ismonitor[/size] :roll: :roll: