View Full Version : Confirm or Deny This Ajax.Request Question

15 Jan 2011, 8:17 AM

I am trying to to implement an Ajax.Request and it is to a different server than the app is hosted on. After creating this I remember the cross-site-scripting limitations. In firebug I never see the request go out and the error is "communication failure".

But, here is the odd thing, when I first created the request I put the headers in incorrectly and was actually getting an unsupported media type error from the remote server. I was also seeing the request in firebug. When I correct the headers I get nothing but the aforementioned error. I get the same result if I comment out the headers completely.

So my question is. Can you with Ajax.Request retrieve data from another server? My code is below and you can see the commented out headers that do not work but are allowing me to talk to the other server.

url: 'http://mca/JSONService.asmx',
method: 'post',
//headers: 'http://mca/scanByHostname',
headers: {
'SOAPAction': 'http://mca/scanByHostname'
xmlData: xmldata,
success: function(response, opts) {
failure: function(response, opts) {

18 Jan 2011, 7:03 AM
Anyone? Buehler?

18 Jan 2011, 7:09 AM
firebug lies.

It runs in the browser chrome context and can do cross site XHR. So when you ask it to show you the net request, it is redoing it and succeeding... where your Ext.Ajax.request has failed.

18 Jan 2011, 7:22 AM
Cross site XHR is not supported by most browsers.

If you are only using one particular browser (e.g. Firefox) then you can do this by configuring the request and your server appropriately (see Mozilla docs).

Another method is using a ScriptTagProxy instead of an Ext.Ajax.request (but a ScriptTagProxy requires a very special server response!).

18 Jan 2011, 7:24 AM
Thanks. I will go lookup the ScriptTagProxy. Outside of that, any other recommendations? I guess I could create a php intermediary on my server that would do the work for me and return the result.

18 Jan 2011, 7:28 AM
Do you really need to write PHP for that?

I assume you are using Apache? In that case you can simply configure a proxy.

18 Jan 2011, 7:32 AM
oh yeah. I am using apache, they are the ones using .net. Didn't even think about that.

18 Jan 2011, 10:25 AM
Thanks! The proxy in apache worked great and was a quick fix.