日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

【翻译】Ext JS 4——Ajax和Rest代理处理服务器端一场和消息的方法

發布時間:2023/11/29 javascript 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【翻译】Ext JS 4——Ajax和Rest代理处理服务器端一场和消息的方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原文:EXTJS4 - Handle Server-side exceptions and message from an Ajax or Rest proxy


作者:Raja


可能要處理的情況:
success(成功)——Ext處理
failure(失敗),由于通訊問題——Ext處理
failure(失敗),由于服務器端異常——開發人員人員必須處理的響應失敗……


解決方案一:
在應用程序控制器中編寫以下方法:

//Ajax Response Error HandlerExt.Ajax.on('requestexception', function(conn, response, options, eOpts) {var error = response.status + ' - ' + response.statusText;console.log('Ajax Request Exception! '+error);if (response.status != 200) { var errorData = Ext.JSON.decode(response.responseText); console.log('ajax req error:'+errorData.message);console.log('Ajax request Error', response.status);}});
解決方案二:
當在服務器端發生異常時,可以將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代理处理服务器端一场和消息的方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。