PDA

View Full Version : Ajax Multiple Servers


vtswingkid
02-04-2008, 04:59 PM
I load my javascript from server X.

I then try to do a Ajax request to server Y.
I am getting a permission denied if my url begins with http://
If the url is something like www.google.com (http://www.google.com) it goes to X/www.google.com.

Do I have to do something special to access another server?

vtswingkid
02-04-2008, 05:08 PM
Here is a snippet:

Ext.onReady(function(){
Ext.Ajax.request({
url: "http://www.google.com",
success: function(o){
debugger;
},
failure: function(o){
debugger;
},
params: {module: 'public'}
});
Ext.Ajax.request({
url: "www.yahoo.com (http://www.yahoo.com)",
success: function(o){
debugger;
},
failure: function(o){
debugger;
},
params: {module: 'public'}
});
}, this);

dawesi
02-04-2008, 08:00 PM
well the browser has security policies that don't allow it because Ext.Ajax uses the httpProxy. you need to use script proxy loader instead.

Docs:
http://cms-dev/ext/2.0.1/docs/?class=Ext.data.ScriptTagProxy

I'm really not sure why a switch wasn't added to Ext.Ajax to check the domain of the request and if it is different, switch to ScriptTagProxy... would be a nice addition.

vtswingkid
02-05-2008, 07:57 AM
thank you!

Oops, this should have been in help.

dawesi
02-10-2008, 07:20 PM
ideally Ext.Ajax should switch modes based on the feeder url... maybe if I write an example that might trigger some thoughts for the core team...

Animal
02-11-2008, 03:20 AM
The latest code drop of my cross-domain Ext.data.Connection includes this.

http://extjs.com/forum/showthread.php?t=17691

There's a function which checks the protocol and host of the requested URL using a RegExp, and if either are different, then it uses a script tag to contact the server.

This means as long as your servers are set up to detect presence of the "callback" parameter and wrap the data in a call to that if it is present, then you can just use Ajax without caring where the server is.

I'm using this on a project right now. The code I'm testing accesses my client's system in Australia. When I run it, it uses script tags, when he runs it, it uses XHRs. So I can load TreePanels without using a custom TreeLoader.

JeffHowden
02-11-2008, 07:16 PM
The only major snag in any of this is when you're trying to use a POST method cross-domain. It simply won't work without some iframe and redirect gymnastics.

vtswingkid
02-11-2008, 08:51 PM
Yeah, I have just given up on the post method. Am happy that every browser I have used still sends cookies!

JeffHowden
02-12-2008, 11:47 AM
I have a working demo that does a POST using an iframe, but haven't ext-ified it yet into a UX. It's possible, just not pretty.