PDA

View Full Version : [Solved] Getting the contents of an URL as a string



DannyR
28 Nov 2007, 9:54 AM
Hi gang -

As part of my arduous process of converting our app from Dojo to Ext, I need the ability to get the contents of an URL (on the same server) back as a string. Of course I could write it from scratch, but I was wondering if: 1. this functionality already exists in the kit somewhere, and 2. if it doesn't, is there an existing I/O API I could leverage?

Any/all help appreciated.

thx,
-d.

tryanDLS
28 Nov 2007, 10:03 AM
You might start with the Ajax class. http://extjs.com/deploy/dev/docs/?class=Ext.Ajax

devnull
28 Nov 2007, 10:05 AM
are you talking about doing a simple xhr request like this?


Ext.Ajax.request({
url : 'handler.php',
params : { param1 : "dosomething" },
success : function(transport){
var text = transport.responseText; //if you just want the result as a string
var obj = Ext.decode(transport.responseText); //if you wanted to turn json into an object
}
});

DannyR
28 Nov 2007, 10:12 AM
Perfection.

You guys are the best!

DannyR
28 Nov 2007, 11:12 AM
One additional follow-up question if you guys would indulge me. Is there any way to force this call to SYNC? If there is, I don't see it in the API - which is surprising because a generic XHR can be either.

thx,
-d.

devnull
28 Nov 2007, 11:20 AM
i believe it is possible, but is considered bad practice unless there is absolutely no other way to do what you want (something which i have yet to see a real world case for).

tryanDLS
28 Nov 2007, 11:21 AM
It's not builtin, but you could look at these threads

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

DannyR
28 Nov 2007, 11:32 AM
i believe it is possible, but is considered bad practice unless there is absolutely no other way to do what you want (something which i have yet to see a real world case for).

It's not that there's NO other way to do it. We are dynamically loading javascript modules, and we've found in the past that SYNC was the most viable approach.

best,
-d.