Posts Tagged ‘API’

Custom Ext JS JsonReader for Google Ajax Search API

October 30th, 2008 by Martin

Well as long term Ext JS fan and user I of course faced with consuming external data resources like for example Google Data API or Google AJAX Search API. The last one mentioned has some really great output and layout capabilities, but I did not want them. I really need only some kind of JSON or XML interface. Google has one – ScriptTag. So after reading this post about creating custom Ext.data.JsonReader and Ext.data.ScriptTagProxy.

/** Ext Proxy for Google Ajax Search **/
Ext.namespace('GoogleAjaxSearch');
 
GoogleAjaxSearch.Proxy = Ext.extend(Ext.data.ScriptTagProxy, {
   url: 'http://ajax.googleapis.com/ajax/services/search/web',
   apiKey: null,
   cx: null,
   callbackParam: 'callback',
 
   constructor: function(config) {
      GoogleAjaxSearch.Proxy.superclass.constructor.call(this, config);
      this.on('beforeload', this.onBeforeLoad, this);
   },
 
   onBeforeLoad: function(o, params) {
      Ext.apply(params, {
         v: 	'1.0',
         rsz: 	'large',
         cx: 	this.cx,
         key: 	this.apiKey,
      }
      );
 
      return true;
   }
});
 
 <a href="http://www.wiso.cz/2008/10/30/custom-ext-js-jsonreader-for-google-ajax-search-api/#more-443" class="more-link"><img src="http://www.wiso.cz/wp-content/themes/wiso/images/more.gif" border="0" style="border:0" alt=" Read More " /></a>
 Tags
Text size: A A