Working with Cakephp Ajax (Prototype)
Posted on | January 30, 2009 | 1 Comment
I have been working on a project that is quite heavy in ajax, using the AjaxHelper in Cakephp.
To note down a couple of things:
- Set up content type for Ajax response
- Pitfall when commenting out codes
- Callback types
1) Set the content type of Ajax response in app_controller beforeFilter()
if($this->RequestHandler->isAjax()) {
Configure::write('debug', 0);
$this->RequestHandler->setContent('javascript', 'text/javascript');
$this->RequestHandler->respondAs('javascript');
$this->layout = 'ajax';
}
Javascript codes returned in the response will be eval as javascript automatically without setting the evalscript:true in the Ajax options.
2) Always use <?php /* ?><?php */ ?> to comment out. I can’t remember how many times this has got me. I always comment out my html instead of deleting them in case they are needed again. Using html <!– //–> to comment out the html code which is mixed with php codes to generate the ajax sorting headers for table or ajax links, will cause javascript errors.
The error message is usually ‘element is null’, triggered somewhere in prototype.js.
Note to myself: Always use php comments to comment unused codes out!
3) The return callbacks to take note of
- loading (onLoading) : this is where you will want to show your loading message, disable the form to prevent user from submitting again by showing a modal message, etcUse $(’msg’).show() to display the loading spinnerResources for spinners
Generator – http://www.ajaxload.info/
More spinner images – http://www.loadinfo.net/ - complete (onComplete) : This is where you will deal with the response from the server. When using Ajax.Updater, the element will be updated automatically with the response. I am also enabling the form or removing the loading message in this callback.Use $(’msg’).hide() to hid the loading spinner
Swf Movie as Background for HTML pages
Posted on | September 16, 2008 | No Comments
Yesterday I got an inquiry about using swf movie as background or masthead banner for a webpage. Is it possible to do that?
I would think that older browsers will show the swf movie with the highest z-index, making it the top most elements. Newer browsers from Firefox2, IE6 onwards would render the z-index correctly.
I came up with a simple html page to test it out. 2 divs behind the flash and 3 in front with one holding a ul navigation.




















