ajaxCFC multithreaded example
Ordered: truefalse
Async: truefalse
Client Side Script
<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>
	
Server Side Script
<cfcomponent extends="ajax">
	
	<cffunction name="echo" output="no" access="private">
		<cfargument name="str" type="string" required="Yes">
		
		<cfreturn arguments.str />
	</cffunction>

</cfcomponent>
	
description This example illustrates the differences between ordered and unordered batches, as well as synchronous and asynchronous.

Ordered batches will force the batch length to remain at (1) at all times, waiting for a response to come back before sending the next call.

Synchronous batches will halt the batch until the callback function has been resolved, making the entire process single threaded.

Note that the synchronous process will take a few seconds… this process in not meant to be used like this, but I wanted to illustrate the consequences. There are extremely handy uses of the synchronous process, which I'll show in a different example.