當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
【翻译】Ext JS 4——Ajax和Rest代理处理服务器端一场和消息的方法
生活随笔
收集整理的這篇文章主要介紹了
【翻译】Ext JS 4——Ajax和Rest代理处理服务器端一场和消息的方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
原文:EXTJS4 - Handle Server-side exceptions and message from an Ajax or Rest proxy
作者:Raja
可能要處理的情況:
success(成功)——Ext處理
failure(失敗),由于通訊問題——Ext處理
failure(失敗),由于服務器端異常——開發人員人員必須處理的響應失敗……
解決方案一:
在應用程序控制器中編寫以下方法:
解決方案二:
當在服務器端發生異常時,可以將500作為響應標頭,原因作為HTML內容發送回客戶端。store.on('loadexception', function(a,conn,resp) { if (resp.status == '304') {Ext.Msg.alert('Content has not changed'); }else if(resp.status == '200') { return; //Do nothing }else if (resp.status == '401') {Ext.Msg.alert('Authentication required - You need to Login'); }else if (resp.status == '302') { errorDialog.body.update('Session Has Expired'); errorDialog.show(); }else if(resp.status == '500') { errorDialog.body.update(resp.responseText); errorDialog.show(); }else{ errorDialog.body.update('An uncaught exception has occured'); errorDialog.show(); } }
解決方案三:
當發送Ajax或REST請求時,Ext JS 4代理通常會預期返回的信息包括參數:data、success和message。參數message是可選的,不過當需要將請求結果顯示給用戶的時候,它就可派上用場了。
function requestMessageProcessor(proxy, response) {if (response && proxy) { try { var responseData = proxy.reader.getResponseData(response);if (responseData.message) {var messageDescription = 'Information'; // title of the alert boxvar messageIcon = Ext.MessageBox.INFO;if (!responseData.success){var messageDescription = 'Error';var messageIcon = Ext.MessageBox.ERROR;}Ext.MessageBox.show({title: messageDescription,msg: responseData.message,buttons: Ext.MessageBox.OK,icon: messageIcon});}}catch(err) {// Malformed response most likelyconsole.log(err);}} } And here’s the part which should reside in proxy:proxy: {...listeners: { exception: function(proxy, response, options) {requestMessageProcessor(proxy, response);}},afterRequest: function(request, success) {requestMessageProcessor(request.scope, request.operation.response);} }
轉載于:https://www.cnblogs.com/hainange/p/6334159.html
總結
以上是生活随笔為你收集整理的【翻译】Ext JS 4——Ajax和Rest代理处理服务器端一场和消息的方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 连续三天梦到蛇是什么意思
- 下一篇: 梦到黄牛是什么征兆