<script type='text/javascript'>_ajaxConfig = {'_cfscriptLocation':'echoTest.cfc', '_jsscriptFolder':'../js'};</script> <script type='text/javascript' src='../js/ajax.js'></script> <script type="text/javascript"> function doMultithreaded() { $('sendButton').value = 'sending ...'; $('sendButton').disabled = true; DWREngine.setOrdered(frm.radioOrdered[0].checked); DWREngine.setAsync(frm.radioAsync[0].checked); // get value from input for (var i = 0; i < 50; i++) { // send data to CF DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'echo', 'string: '+i, doMultithreadedResult); } } // call back function function doMultithreadedResult (r) { // appends response to div $('echoScreen').innerHTML = $('echoScreen').innerHTML + '<BR>' + 'current batch len: ' + DWREngine._batches.length + '; returned string: ' + r; if (DWREngine._batches.length == 1 || DWREngine._batches.length == 0) { $('sendButton').value = 'send another 50 requests'; $('sendButton').disabled = false; } } </script> <fieldset> <legend>ajaxCFC multithreaded example</legend> <!--- onSubmit validate form ---> <form name="frm"> <table width="800"> <tr> <td> Ordered: true<input type="Radio" name="radioOrdered" value="true">false<input type="Radio" name="radioOrdered" value="false" checked><br> </td> <td> Async: true<input type="Radio" name="radioAsync" value="true" checked>false<input type="Radio" name="radioAsync" value="false"><br> </td> <td> <input type="button" id="sendButton" value="send 50 requests" onclick="doMultithreaded()"> </td> <td> <input type="Button" value="clear screen" onclick="$('echoScreen').innerHTML = '';"> </td> </tr> </table> </form> <div id="echoScreen" style="height: 200px;overflow: scroll;"></div> </fieldset>
<cfcomponent extends="ajax"> <cffunction name="echo" output="no" access="private"> <cfargument name="str" type="string" required="Yes"> <cfreturn arguments.str /> </cffunction> </cfcomponent>