Upgrade to ExtJS 3.2.0 - Released 03/30/2010
[extjs.git] / docs / source / JsonProvider.html
1 <html>
2 <head>
3   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    
4   <title>The source code</title>
5     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
7 </head>
8 <body  onload="prettyPrint();">
9     <pre class="prettyprint lang-js">/*!
10  * Ext JS Library 3.2.0
11  * Copyright(c) 2006-2010 Ext JS, Inc.
12  * licensing@extjs.com
13  * http://www.extjs.com/license
14  */
15 <div id="cls-Ext.direct.JsonProvider"></div>/**
16  * @class Ext.direct.JsonProvider
17  * @extends Ext.direct.Provider
18  */
19 Ext.direct.JsonProvider = Ext.extend(Ext.direct.Provider, {
20     parseResponse: function(xhr){
21         if(!Ext.isEmpty(xhr.responseText)){
22             if(typeof xhr.responseText == 'object'){
23                 return xhr.responseText;
24             }
25             return Ext.decode(xhr.responseText);
26         }
27         return null;
28     },
29
30     getEvents: function(xhr){
31         var data = null;
32         try{
33             data = this.parseResponse(xhr);
34         }catch(e){
35             var event = new Ext.Direct.ExceptionEvent({
36                 data: e,
37                 xhr: xhr,
38                 code: Ext.Direct.exceptions.PARSE,
39                 message: 'Error parsing json response: \n\n ' + data
40             });
41             return [event];
42         }
43         var events = [];
44         if(Ext.isArray(data)){
45             for(var i = 0, len = data.length; i < len; i++){
46                 events.push(Ext.Direct.createEvent(data[i]));
47             }
48         }else{
49             events.push(Ext.Direct.createEvent(data));
50         }
51         return events;
52     }
53 });</pre>    
54 </body>
55 </html>