PDA

View Full Version : Cross Domain JSONP call with Ext.Ajax.request



cavalleydude
15 Nov 2010, 2:48 PM
I have a question regarding cross domain web service calls. I've read all the docs, but I'm still confused on how a standard connection uses cross domain calls (without using an explicit Store object with a scriptTagProxy).

Previously, all our web services and web-client were located on a single web server. We just implemented JSONP and we now deploy web services across a variety of servers, now I need to implement JSONP cross domain service calls.

This is the code I use now (just standard JSON requests), some services do not use a Store object, instead uses an Ext.data.Connection request to handle direct connection/request of data.



var dataconn = new Ext.data.Connection();

dataconn.on('requestcomplete', function( dataconn, response ){
// SUCCESS
// handle success

}, this);

dataconn.on('requestexception', function( dataconn, response ){
// handle error condition
}, this);

dataconn.request( {
headers: {
'Authorization' : authBasic
},
url:'/authService',
params: {
'realm' : realm
},
method : 'POST',
scope:this
} );

My question is how do I convert this to JSONP cross domain call, the web service is expecting a callback to wrap the content into. I tried this... but I keep getting "Connection failure" errors.



Ext.Ajax.request( {
headers: {
'Authorization' : authBasic
},
url:'http://anotherserver.mycomp.com/authService',
params: {
'realm' : realm
},
scriptTag: true,
callback:this.myResponseFn,
method : 'POST',
scope:this
} );

myResponseFn: function( options, success, response ) {
// gets called, but success is false, response content does not contain any data
}

I keep getting "Connection Failure" in the response. Is this even possible? I must be missing something... any help would be greatly appreciated.

PS: Using the latest Ext-JS libs.

-cavalleydude

cavalleydude
16 Nov 2010, 8:32 AM
I found this topic on this forum:

http://www.sencha.com/forum/showthread.php?110392-Ajax-domain-issues&highlight=jsonp

It looks like the answer for my needs may simply be to adjust the configuration on our internal servers (read the article... look for "Got it!" back-end server changes). I'll give it a try. I have multiple web services running on multiple hosts within the same domain.