|
Mailing Lists
|
Home /
Groups /
Ajax
Anybody have a good cross browser HTTP Request object for JavaScript
I've been building my own and have been having some trouble (I've attached my current code below).Jim Davis 04/04/05 03:19 P I like this one:Massimo Foti 04/05/05 03:29 A This'n tooRob 04/05/05 01:39 P > I've been building my own and have been having some trouble (I'veJehiah Czebotar 05/16/05 10:42 P I've been building my own and have been having some trouble (I've attached my current code below). I'd really like to do two things: 1) Make this cross platform. This I know I can do - I just have to do browser detection and add httpxmlrequest. 2) Make this a "real" JavaScript object. I'd love to be able to instantiate the object and call a "send" method either synchronously (the method wouldn't return until it got the data or timed out) or asynchronously (the method would return immediately but still fetch the data). I would also like the whole message to be thread safe. The latter stuff is where I'm having the problem. I figure that this is something everybody is facing with this stuff so that it all must have been solved by now. ;^) The current function I'm using is below. Not that you can instantiate the objects in an "App" object ( a sort or psuedo-scope borrowed from CF) to prevent tons of objects from being created. However this solution isn't thread safe. Also I use two different objects because one of them can't do SSL and the other can't do local files. Right now this code only runs in IE 6 and is designed for use in an HTA application. I'd really like (wouldn't we all) a nice, simple, service that abstracts all of the browser differences away and is still completely capable. Thanks in advance, Jim Davis // Function to get content via HTTP function LoaderHTTP(URL, Method, Parameters) { // If present turn the Parameters object into a string if ( typeof Parameters == "object" ) { var ParametersList = ""; for ( var CurProp in Parameters ) { if ( typeof Parameters[CurProp] != "function" ) { ParametersList = ParametersList + CurProp + "=" + Parameters[CurProp] + "&"; }; }; }; // Init the HTTP object if ( URL.toLowerCase().indexOf("http://") < 0 && URL.toLowerCase().indexOf("https://") < 0 ) { if ( typeof App.HTTPOb_XML == "undefined") { var HTTPOb = new ActiveXObject("Microsoft.XMLHTTP"); } else { var HTTPOb = App.HTTPOb_XML; }; } else { if ( typeof App.HTTPOb_WIN == "undefined") { var HTTPOb = new ActiveXObject("WinHttp.WinHttpRequest.5.1"); } else { var HTTPOb = App.HTTPOb_WIN; }; }; // Init the HTTP Object HTTPOb.Open( Method, URL, false ); // Set the encoding type, if needed if ( Method.toLowerCase() == "post" ) { HTTPOb.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); }; // Send the data HTTPOb.Send(ParametersList); // Return return HTTPOb.responseText; }; I like this one: http://sourceforge.net/projects/sarissa/ This may be worth a check too: http://xmljs.sourceforge.net/index.html ---------------------------- Massimo Foti DW tools: http://www.massimocorner.com CF tools: http://www.olimpo.ch/tmt/ ---------------------------- This'n too http://www.robrohan.com/projects/neuromancer/ On Apr 5, 2005 12:19 AM, Massimo Foti <massimo@amila.ch> wrote: ----- Excess quoted text cut - see Original Post for more ----- ----- Excess quoted text cut - see Original Post for more ----- I have been using DataRequestor by Mike West and though it hasn't gotten much press, it is roubust and works well. (and he should be releasing an update soon that adds JSON support) you use it like so: var req=new DataRequestor(); req.onload = function init(){ alert("we got the data");} req.setObjToReplace("element-id"); req.addArg(_POST,"method","savedata"); req.getUrl("http://...."); http://mikewest.org/projects.php?action=viewProject&projectID=1
|
May 16, 2012
|
Latest Fusion Authority Articles
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||