r8 - 18 Mar 2008 - 07:36:20 - Main.DovKatzYou are here: TWiki >  AjaxCookbook Web > HowToEnableCrossDomainAccessInExt

Ext "Flash-enhanced" connections for Cross-domain access

by Dov Katz, and Imran Ahmad

About

This demo uses F4A, a SWF which allows you to make the equivalent of XHR's via flash (leveraging Flash's HTTP requests) to access cross-domain URL's (as long as the appropriate crossdomain.xml file permits it).

I use F4A with a small wrapper (see all attachments below) and set up an instance on the page. I then extend the Ext connection in a way that lets you specify flashProxy as an attribute of the Ext.data.HttpProxy to use flash to make the requests.

For some reason, it doesn't work all the time with XML documents (I'm sure it's my faulty parsing logic as I try to do a Javascript-base creation of the DOM Document based on the text payload I get as a callback from Flash.)

The other challenge is that I had to add a "beforeload" event whenever the flashProxy is used, to avoid a race condition when things are set up. If the flash proxy is not fully set up yet, I create a closure with the load() call being run, and return false to prevent it from running. I setTimeout/defer it to call my closure method in 200 ms. This would repeat until the flash is initialized, but it's usually a sub-second operation.

Actual Demo

Demo Grid

This grid searches Yahoo's Search API for "Jack Slocum" images.

Demo: Source Code

<!--
      * Set NOAUTOLINK = on
-->
<script src="http://www.cachefile.net/scripts/ext/2.0.1/adapter/yui/yui-utilities.js"></script>
<script src="http://www.cachefile.net/scripts/ext/2.0.1/adapter/yui/ext-yui-adapter.js"></script>
<link rel="stylesheet" href="http://www.cachefile.net/scripts/ext/2.0.1/resources/css/ext-all.css">
<script src="http://www.cachefile.net/scripts/ext/2.0.1/ext-all.js"></script>
<script src="%PUBURL%/%WEB%/%TOPIC%/swfobject.js"></script>
<script src="%PUBURL%/%WEB%/%TOPIC%/f4a_js.js"></script>
<script>
// since the swf is a wiki attachment, I made the Ext extension "absorb" the variable...
var _SWF_URI='%PUBURL%/%WEB%/%TOPIC%/f4a.swf';
</script>
<script src="%PUBURL%/%WEB%/%TOPIC%/Ext.FlashProxySupport.js"></script>

<script>
var response;


var reader=new Ext.data.JsonReader({
       root:'ResultSet.Result'
       },
         [
            {name: 'Title', mapping: 'Title'},
            {name: 'Summary', mapping: 'Summary'},
           {link: 'Url', mapping: 'Url'},
            {name: 'Thumbnail', mapping: 'Thumbnail'}
        ]);


var store= new Ext.data.Store({
proxy:new Ext.data.HttpProxy({
url: 'http://search.yahooapis.com/ImageSearchService/V1/imageSearch',
             flashProxy: true,
                method:"GET"
}), 
 baseParams:{appid:'YahooDemo', output:'json'},
reader:reader
});

var grid="";

function renderThumb(v){
   return "<img src='"+v.Url+"' height='80' />";
}

var cm=new Ext.grid.ColumnModel([
  {header:'Title', dataIndex:'Title'},
  {header:'Thumbnail', dataIndex:'Thumbnail', renderer:renderThumb},
  {header:'Summary', dataIndex:'Summary'}
]);
cm.defaultSortable=true;



Ext.onReady(function(){

 var grid=new Ext.grid.GridPanel({ 
 sm:new Ext.grid.RowSelectionModel({singleSelect:true}),
 store:store, 
loadMask:true,
 cm:cm,width:700,height:500,
 renderTo:'grid', title:'Search Items', frame:true
});


});

Ext.onReady(function(){store.load({params:{ query:'Jack Slocum'}});});

File Attachments

Topic attachments
I Attachment Action Size Date Who Comment
jsjs Ext.FlashProxySupport.js manage 6.6 K 18 Mar 2008 - 06:54 Main.DovKatz  
elseswf f4a.swf manage 1.0 K 09 Mar 2008 - 17:29 Main.DovKatz  
jsjs f4a_js.js manage 2.7 K 09 Mar 2008 - 17:29 Main.DovKatz  
jsjs swfobject.js manage 6.7 K 09 Mar 2008 - 17:31 Main.DovKatz  

Edit | Attach | Printable | Raw View | Backlinks: Web, All Webs | History: r8 < r7 < r6 < r5 < r4 | More topic actions
AjaxCookbook.HowToEnableCrossDomainAccessInExt moved from Sandbox.TestTopic8 on 18 Mar 2008 - 07:27 by Main.DovKatz - put it back
 
Powered by TWiki
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback