Remote AJAX events
Another place where we can show the power of code reuse within COOP and the coprocessor is in AJAX calls. Here we will make one final adjustment to the events code example to show the power of what can be done. This time, we won't even need to modify the coprocessor. We have already set the access mode of the setHit()
function to remote
early in this chapter. This will allow us to call this method remotely with AJAX. Here is the code we would add to our JavaScript segment, right after the reset method call:
$('#stats').click(function () { <cfoutput> $(this).load("#coop.get_ajaxService('setHit')#"); </cfoutput> });
Now while we generally seek to keep the view separate from any programming logic, exceptions are allowed. You can see how we wrapped a section of the code with CF output. Then we called the COOP object with a get service method. We pass the name of the remote method into the function. This lets us copy this code to another COOP CFC and it will...