I have a problem with some Javascript where I set off a setCallbackHandler() and I need it to complete prior to continuing through the rest of my code. Below is an example, by the time I get to my alert(count) the setCallbackHandler is still processing.
I believe I need to have a Sync call rather than an Async, but I haven’t had any luck implementing any… Any suggestions? Thanks in advance.
function checkPerson(r){
if(r){
count++
}
else{
alert("None Found");
}
}
var g = new cfc_method();
g.setCallbackHandler(checkPerson);
g.returnIds(user_id);
alert(count);
Any code that must run after the request completes should be in the callback handler. I would not recommend changing cfajax calls to sync, however, if you must, you can call
g.setSyncMode()to set the call mode to synchronous. Note that in synchronous mode, the data is returned directly from the cfc method call, not to the callback handler.