House of Fusion
Search over 2,500 ColdFusion resources here
  
Home of the ColdFusion Community

Mailing Lists
Home /  Groups /  Ajax

Anybody have a good cross browser HTTP Request object for JavaScript

  << Previous Post |  RSS |  Sort Oldest First |  Sort Latest First |  Subscribe to this Group Next >> 
Top  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Jim Davis
04/04/2005 03:19 PM

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; };

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Massimo Foti
04/05/2005 03:29 AM

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/ ----------------------------

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Rob
04/05/2005 01:39 PM

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 -----

Top  |   Parent  |   Reply  |   Original Post  |   RSS Feed  |   Subscribe to this Group
Author:
Jehiah Czebotar
05/16/2005 10:42 PM

----- 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


<< Previous Thread Today's Threads Next Thread >>

Search ajax

May 16, 2012

<<   <   Today   >   >>
Su Mo Tu We Th Fr Sa
     1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31     

Designer, Developer and mobile workflow conference