JsonProvider.js
上传用户:dawnssy
上传日期:2022-08-06
资源大小:9345k
文件大小:1k
源码类别:

JavaScript

开发平台:

JavaScript

  1. /*!  * Ext JS Library 3.1.0  * Copyright(c) 2006-2009 Ext JS, LLC  * licensing@extjs.com  * http://www.extjs.com/license  */ /**
  2.  * @class Ext.direct.JsonProvider
  3.  * @extends Ext.direct.Provider
  4.  */
  5. Ext.direct.JsonProvider = Ext.extend(Ext.direct.Provider, {
  6.     parseResponse: function(xhr){
  7.         if(!Ext.isEmpty(xhr.responseText)){
  8.             if(typeof xhr.responseText == 'object'){
  9.                 return xhr.responseText;
  10.             }
  11.             return Ext.decode(xhr.responseText);
  12.         }
  13.         return null;
  14.     },
  15.     getEvents: function(xhr){
  16.         var data = null;
  17.         try{
  18.             data = this.parseResponse(xhr);
  19.         }catch(e){
  20.             var event = new Ext.Direct.ExceptionEvent({
  21.                 data: e,
  22.                 xhr: xhr,
  23.                 code: Ext.Direct.exceptions.PARSE,
  24.                 message: 'Error parsing json response: nn ' + data
  25.             })
  26.             return [event];
  27.         }
  28.         var events = [];
  29.         if(Ext.isArray(data)){
  30.             for(var i = 0, len = data.length; i < len; i++){
  31.                 events.push(Ext.Direct.createEvent(data[i]));
  32.             }
  33.         }else{
  34.             events.push(Ext.Direct.createEvent(data));
  35.         }
  36.         return events;
  37.     }
  38. });