Thanks for the solution and the explanation. Same to you James. :)

Jim Davis wrote:
>> -----Original Message-----
>> From: Phillip M. Vector [mailto:[EMAIL PROTECTED]
>> Sent: Sunday, July 15, 2007 10:24 PM
>> To: CF-Talk
>> Subject: Prototype/AJAX Neubie question
>>
>> Can someone tell me how I can have 2 separate ajax threads?
>>
>> Whenever I run the code below, it works as long as only 1 is triggered
>> at a time.
>>
>> How do I make essentially 2 separate AJAX calls and keep the data
>> coming
>> back separate?
> 
> James answered you question, but I thought this might help as well:
> 
> http://www.depressedpress.com/Content/Development/JavaScript/Extensions/DP_R
> equestPool/Index.cfm
> 
> It's a pooler implementation for HTTP requests in JavaScript.  Essentially
> it manages the creation of a set number of request objects and a single
> queue for making requests.  As you add requests to the queue they will be
> assigned to any free request object.
> 
> In your case you could just create the pool with two objects like so:
> 
> myRequestPool = new DP_RequestPool(2);
> 
> Then start the queue polling (here we're checking for new queue items every
> 100 ms):
>  
> myRequestPool.startInterval(100);
> 
> Requests are objects that simplify the process of passing data and assigning
> handlers.  In your case a request might look like this (assuming the above
> two lines were already included):
> 
> function showmessages() {
> 
>       var url = "CheckMessages.cfm";
>       url = url+"&room="+document.getElementById("Room").value;
>               // Create the Request
>       var CurRequest = new DP_Request("GET", url, null, stateChanged);
>               // Add the request to the pool
>       myRequestPool.addRequest(myRequest);
> 
> };
> 
> That function creates a new request and adds in to the request pool.  The
> new free request object will perform it.  It will then call the handler
> specified and, automatically, pass the value of "responseText" to it as the
> first argument.  You handler function would change a bit (you no longer need
> to worry about ANY request handling in the handler:
> 
> function stateChanged(NewContent) {
>       document.getElementById("Messages").innerHTML = NewContent;
> };
> 
> That's it - the pooler does all the grunt work: manages the objects,
> readyStates, etc.  It can also automatically timeout a request after a set
> period and can automatically retry a request a specified number of times
> before giving up.
> 
> Also using the Request object you can easily create requests that pass
> parameters to the called page and pass extra values to the handler.  Say,
> like in your example, that the "CheckMessages.cfm" expects a parameter - you
> don't have to do that string manipulation.  Just pass an object with one
> property, "room", to the request constructor like so (the braces are
> JavaScript literal for "object"):
> 
>       var CurRequest = new DP_Request(
>               "GET",
>               "CheckMessages.cfm",
>               {"room" : document.getElementById("Room").value},
>               stateChanged);
> 
> That will create a "room" parameter with the proper value appropriate to the
> method ("GET" or "POST") that you use.
> 
> Lastly you can also pass extra information to the handler.  The Request
> constructor takes an optional last argument: an array of values to be passed
> as second through whatever arguments to the handler (remember the first
> argument is always the responseText).  Let's say that you wanted to pass the
> value of "Room" to the handler as well; you'd do this (not that the square
> brackets are literal notation for an array):
> 
>       var CurRequest = new DP_Request(
>               "GET",
>               "CheckMessages.cfm",
>               {"room" : document.getElementById("Room").value},
>               stateChanged,
>               [document.getElementById("Room").value]);
> 
> Your handler could then be changed to this:
> 
> function stateChanged(NewContent, RoomValue) {
>       document.getElementById("Messages").innerHTML = RoomValue + " " +
> NewContent;
> };
> 
> The library itself is small and should simplify your coding - your calls and
> handlers have NO direct responsibility to the request (no chcking
> readyStates or response values or constructing URLs or Form field parameters
> by hand).  It's completely independent - it doesn't require a framework
> (although it will work with any framework) or any particular coding style.
> If you also grab DP_Debug (my debugging library, linked from the docs) it
> will automatically take advantage of it (it really helps) but it's not
> required at all.
> 
> I've found it incredibly useful - I hope you do as well.
> 
> Jim Davis
> 
> 
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Upgrade to Adobe ColdFusion MX7
The most significant release in over 10 years. Upgrade & see new features.
http://www.adobe.com/products/coldfusion?sdid=RVJR

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:283747
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to