View Full Version : Can I make an ajax call to another server?

28 Aug 2009, 11:52 AM
I am trying to call a centralized server for simple authentication purposes in an intranet environment. Can this be done, or does the call have to be in the same web root?

Thanks for any advice.

url: 'http://someserver/webservice/TestService',
method: 'post',
params: {
username: a1ws23,
password: 'testadm1n'

success: function(response, options) {

failure: function(response, request) {
alert('Failed - ' + response.status);

29 Aug 2009, 3:04 AM
You could use a ScriptTagProxy (or the cross-domain Ext.Ajax (http://www.extjs.com/forum/showthread.php?t=17691) user extension).

But be aware of the requirements for ScriptTagProxy (read the API docs carefully)!

29 Aug 2009, 5:28 AM

Would you have a small example please?


29 Aug 2009, 5:58 AM
look to feed-viewer example!

29 Aug 2009, 6:59 AM
or the examples/form/custom.html example in your SDK

30 Aug 2009, 5:13 AM
That will work Animal - Thanks!

Mike Robinson
30 Aug 2009, 5:28 AM
What I usually do, for a variety of reasons, is to send all of the calls to one server, and if that server needs to "ask for help from someone else," then let it be the one to do it.

The basic reason for this is ... timing. If you've got several different asynchronous request streams going on at the same time to different servers, then you can lose control of what's going on in a great big hurry. This creates software that's very, very difficult to debug ... stuff that's going to "fail in front of the end-user." Not what you want.

Also... it's usually the case that the host-side components need to be aware of each other. They probably need a reliable, trustworthy way for "the left hand to know what the right hand is doing." Well, the client-side is neither reliable nor trustworthy.

So... let there be a "single point of contact" for the client-side application to talk to. If there needs to be communication among server-side components, let them securely discuss things among themselves without further involving the client.

It's not a matter of "is it possible to do it this-way or that." (The answer is, "yes.") It comes down to what is most likely to be most "RASS = Reliable, Available, Secure, Serviceable."

31 Aug 2009, 9:01 AM
The code below should return JSON data. I am being forced to return XML.
Can anyone give some advice on making this work? Thanks,

Here is the XML being returned from the service:

<read status="test" secure="false">

function loadApp() {
var ds = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
url: 'http://webservice/TestService',
method: 'post',
params: { username: me, password: 'adm1n' }
reader: new Ext.data.JsonReader({
root: 'data',
id: 'username'
Fields: [
{ name: 'username', mapping: 'username', type: 'string' },
{ name: 'password', mapping: 'password', type: 'string' }


31 Aug 2009, 10:57 AM
If you had taken Condor's advice you would realize that XML cannot be used.

The name ScriptTagProxy gives a hint, and the documentation makes it explicit.

A <script src="http://webservice/TestService?username=me&password=admin"></script> tag is added to the page.

That's how you can talk to a "foreign" site.

So obviously, as the documentation says, what must be returned is executable Javascript. Calling, as the documentation says, the specified callback function to inject the data into Ext.