source:
trunk/workshop-routing-foss4g/web/ext/src/direct/JsonProvider.js
@
77
Revision 76, 1.2 KB checked in by djay, 13 years ago (diff) | |
---|---|
|
Line | |
---|---|
1 | /*! |
2 | * Ext JS Library 3.4.0 |
3 | * Copyright(c) 2006-2011 Sencha Inc. |
4 | * licensing@sencha.com |
5 | * http://www.sencha.com/license |
6 | */ |
7 | /** |
8 | * @class Ext.direct.JsonProvider |
9 | * @extends Ext.direct.Provider |
10 | */ |
11 | Ext.direct.JsonProvider = Ext.extend(Ext.direct.Provider, { |
12 | parseResponse: function(xhr){ |
13 | if(!Ext.isEmpty(xhr.responseText)){ |
14 | if(typeof xhr.responseText == 'object'){ |
15 | return xhr.responseText; |
16 | } |
17 | return Ext.decode(xhr.responseText); |
18 | } |
19 | return null; |
20 | }, |
21 | |
22 | getEvents: function(xhr){ |
23 | var data = null; |
24 | try{ |
25 | data = this.parseResponse(xhr); |
26 | }catch(e){ |
27 | var event = new Ext.Direct.ExceptionEvent({ |
28 | data: e, |
29 | xhr: xhr, |
30 | code: Ext.Direct.exceptions.PARSE, |
31 | message: 'Error parsing json response: \n\n ' + data |
32 | }); |
33 | return [event]; |
34 | } |
35 | var events = []; |
36 | if(Ext.isArray(data)){ |
37 | for(var i = 0, len = data.length; i < len; i++){ |
38 | events.push(Ext.Direct.createEvent(data[i])); |
39 | } |
40 | }else{ |
41 | events.push(Ext.Direct.createEvent(data)); |
42 | } |
43 | return events; |
44 | } |
45 | }); |
Note: See TracBrowser
for help on using the repository browser.