Welcome to the seventh entry in the Intermediate ColdFusion Contest. The earlier entries may be found at the end of this post. Today’s entry is from Jason Fill. Before reading on, please check his application here. You can download his code from the download link at the bottom. Please respect the copyright of the creator. The first thing I noticed was how the page updated. It was obviously DHTML (or AJAX, or whatever you wanted to call it), so I dug a bit into his code. I’m going to cheat a bit and make my writing a bit easier by quoting his docs from play.cfm:
As you will see below, the doRequest() function is the main JS function that is called. Basically, that function dynamically writes JS code to the page by using the create element method. So we call a specific function based on what we need to do, for example if the player wants to hit, we call the playerHit() function which sets the the actual page we want to call, then from within the playerHit() function we call the doRequest() function to create the element on the page. When the element is created on the page it actually makes the call to the url that we set in the original function playerHit() and that does the page rendering behind the scenes. If you look at the template that it calls playerhit.cfm. You will see all the code that works behind the scenes to perform the actual player hit. Then at the bottom of the page you will see 2 additional function calls - updatePlayer() and showTable().
// this is the core of all the functions. It will make the request happen
// create < script > element
// assig n < script > attributes
// append element to document tree & send GET request
Now for the bugs. I was able to confuse (and break) the application by hitting back after I my bank was empty. The game reported I had (25) in the bank, which I suppose is it’s way of reporting negative 25. After I tried to play though it just kind of hung there.
I also swear I saw the dealer stay once on 16 - but I didn’t see it happen again.
As with many other submissions, his CFC doesn’t use var scoping. (Yes, I’m getting to be a bit crazy about it, aren’t I?)