ColdFusion automatically determines whether a function call is synchronous or asynchronous. However, if you need to invoke an asynchronous function in a synchronous mode, you can use the invokeCFClientFunction function. The function call just needs to be wrapped around with the invokeCFClientFunction function call. For instance, invokeCFClientFunction(myAsyncFunc(arg1,arg2)).
The invokeCFClientFunction function can be used to invoke both synchronous and asynchronous CFML functions from JavaScript.
ColdFusion 11: Added this function
invokeCFClientFunction(funcName, arg1, arg2, …., successCallback)
Parameter |
Description |
|---|---|
funcname |
Required. The function to be invoked. |
arguments |
Optional. Arguments to pass to the function. |
| succesCallback | The callback handler when the function gets invoked successfully. The successCallback argument is mandatory. If there is no successCallback, use null. |
The following code depicts a simple usage of file creation on the device. Since file creation is an asynchronous operation, we are using the invokeCFClientFunction to invoke this function.
<cfclientsettings enableDeviceAPI=true>
<cfclient>
<cffunction access="public" name="createfile" returntype="void" >
</cffunction>
</cfclient>
File name : <input id="filename" type="text"/>
<button onclick="invokeCFClientFunction('createfile',null)">Create a file</button>
<br> <b>Result :</b><div id="result"></div>
<script type="text/javascript">
function showresult(obj)
{
return JSON.stringify(obj);
}
</script>
For more information on using this function, see this community blog post.
Sign in to your account