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

	<legend>ajaxCFC multithreaded example</legend>
		<!--- onSubmit validate form --->
			<form name="frm">
			<table width="800">
						Ordered: true<input type="Radio" name="radioOrdered" value="true">false<input type="Radio" name="radioOrdered" value="false" checked><br>
						Async: true<input type="Radio" name="radioAsync" value="true" checked>false<input type="Radio" name="radioAsync" value="false"><br>
						<input type="button" id="sendButton" value="send 50 requests" onclick="doMultithreaded()">
						<input type="Button" value="clear screen" onclick="$('echoScreen').innerHTML = '';">
			<div id="echoScreen" style="height: 200px;overflow: scroll;"></div>
Server Side Script
<cfcomponent extends="ajax">
	<cffunction name="echo" output="no" access="private">
		<cfargument name="str" type="string" required="Yes">
		<cfreturn arguments.str />

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.