Sorry - in my last message I said you'd need to load "DP_PanelManager" at the end... ignore me. You will of course need to load "DP_RequestPool" instead. ;^)
Jim Davis > -----Original Message----- > From: James Smith [mailto:[EMAIL PROTECTED] > Sent: Monday, December 17, 2007 6:25 AM > To: CF-Community > Subject: RE: JS HTTP Request? > > Ok, could I have some help... > > function updateMinSale(rowNum) { > var tempURL = > 'http://127.0.0.1/cfc/calculators.cfc?method=minPriceCalc&productgroupi > d=2&c > ostprice=2'; > myRequestPool = new DP_RequestPool(); > myRequest = new DP_Request("GET",tempURL); > document.getElementById("min" + rowNum).value = WHATGOESHERE; > } > > For testing I am using the URL set in the tempURL variable, the > parameters > will change later but will do for now. The CFC returns a simple > numeric > value like... > > <wddxPacket > version='1.0'><header/><data><number>2.26</number></data></wddxPacket> > > What would I put in the code in place of WHATGOESHERE to set the value > of > the form field to (in this example) 2.26? > > -- > Jay > > -----Original Message----- > From: Jim Davis [mailto:[EMAIL PROTECTED] > Sent: 14 December 2007 18:13 > To: CF-Community > Subject: RE: JS HTTP Request? > > > -----Original Message----- > > From: James Smith [mailto:[EMAIL PROTECTED] > > Sent: Friday, December 14, 2007 8:13 AM > > To: CF-Community > > Subject: JS HTTP Request? > > > > I need to use some complex calculations from a CFC to update a form > > field > > when a different field is changed. This seems like a fairly simple > > matter > > of using... > > > > onChange="getHttp();" > > It's not going to be quite that simple, but I've a component which will > make > it much simpler here: > > http://www.depressedpress.com/Content/Development/JavaScript/Extensions > /DP_R > equestPool/Index.cfm > > It's a completely abstracted JavaScript HTTP Request pool - runs in all > major browsers and doesn't require any server-side code. > > On your page you instantiate the pool (at the top, onload(), wherever) > and > start it's polling mechanism: > > // Instantiate the Pool > myRequestPool = new DP_RequestPool(4); > // Start the Interval > myRequestPool.startInterval(100); > > This checks for new requests every 100 ms. (There's also a > "stopInterval()" > as well which will stop all queued requests from being processed). > > To make a request you create a "DP_Request" object and add it to the > queue > using the addRequest() method. At its simplest form (call a page and > do > nothing) it looks like this: > > var myRequest = new DP_Request("GET","http://www.mysite.com/Add.htm") > myRequestPool.addRequest(myRequest); > > Requests can be reused over and over, if you like, just by adding them > to > the queue again. > > That's not that useful however, so you can also pass parameters to the > page > being called (as an object containing name=value pairs) and a handler > (a > function to call when complete which will do something with the > result). > > In your case its simplest to think about this as two functions: one to > make > the request, one to handle the response. > > function getHTTP() { > var myRequest = new DP_Request( > "GET", > "http://www.mysite.com/whatever.cfm", > null, > handleHTTP); > myRequestPool.addRequest(myRequest); > }; > > This function (called as in your example) creates a new request and > puts it > on the queue. The "null" in the request is where input parameters > would go. > You can include an object here or create one inline using object > literal > notation (ask if you need more information). > > The "handleHTTP" (no parens) is the function that will be called with > the > output from the call. The first argument passed to ANY handler > function is > the results of the HTTP call. It might look like this: > > function handleHTTP(results) { > document.getElementById("myFormField").value = results; > }; > > This is really simple of course but all it's doing is dumping the > results > into the field (change this to however you want to use the value). > > That's it. > > There are actually a few ways to streamline this but all of them need > more > explanation that won't really add to the solution. In short tho: > > +) You could easily reuse the Request object. This is a good idea if > the > object really doesn't change (as in the example) but gets more > dangerous if > the properties change. Remember objects are accessed by reference so > any > changes to the object will affect all of those in the queue waiting to > be > serviced - this can be useful sometimes but only if you really "get" > what's > going on. > > +) The handler function, especially if it's really that simple, could > be > built inline as an anonymous function (a "closure"). This could simply > your > code a bit but that's about it. For more complex scenarios this can be > life > saver however if the handler code needs to change with the > circumstances of > the call. > > +) You don't really need function to do the call, you could do all that > work > right in the "onchange" handler itself (create and add the request, or > just > add it if you're using a pre-built request) but it could get messy. > > I'd be happy to help with this further if you want to post a longer > snippet > of the code you're working on. > > Jim Davis > > > > > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Adobe® ColdFusion® 8 software 8 is the most important and dramatic release to date Get the Free Trial http://ad.doubleclick.net/clk;160198600;22374440;w Archive: http://www.houseoffusion.com/groups/CF-Community/message.cfm/messageid:248492 Subscription: http://www.houseoffusion.com/groups/CF-Community/subscribe.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.5