An Ajax link is not logic. It’s a link that behaves differently from a regular link. This is the thing, we are not talking about separation of layout from logic, but the separation of javascript entirely from layout (which is impossible anyway, even with jQuery). These are two different things. It is entirely impossible to separate logic from layout, even using template engines. The separation of business logic from presentation logic is a good thing, however you will never remove logic from presentation entirely. We just have two types of logic.
What we are talking about is a link such as my example as opposed to click functions written to the DOM instead. The first scenario is cleaner in all respects and adheres better to the concept of separation.
Now, let us compare the actual code side by side using Cooper’s example for a better look:
- creating an Ajax link using ajaxLink().
<ul class="categoryList">
<?php foreach($this->getCategoryList() as $category) { ?>
<li>
<?php echo CHtml::ajaxLink(CHtml::encode($category->categories_name),array('categories/show', 'id' => $category->id), array('update' => '#content'), array('href' => 'index.php?r=categories/show&id=' . $category->id)); ?>
</li>
<?php } ?>
</ul>
- a typical ‘hard coded’ Ajax link using jQuery:
<ul class="categoryList">
<?php foreach($this->getCategoryList() as $category) { ?>
<li>
<a href="index.php?r=categories/show&id=<?php echo $category->id; ?>" onclick="jQuery.ajax({'url':'index.php?r=categories/show&id=<?php echo $category->id; ?>','cache':false,'success':function(html){jQuery('#content').html(html)}});return false;"><?php echo $category->categories_name; ?></a>
</li>
<?php } ?>
</ul>
Ok, the first method is definitely less code to write, however it is a simple enough matter to write a PHP function() to output the ‘hard’ link. Both methods rely equally on the output of business logic. Technically, there is no difference in that respect.
Let us look at the HTML output which is far more important if we have a lot of Ajax links in the application:
- Typical output using the ajaxLink() function:
<ul class="categoryList">
<li>
<a href="index.php?r=categories/show&id=52" id="yt0">Romance</a></li>
<li>
<a href="index.php?r=categories/show&id=53" id="yt1">Mystery</a></li>
<li>
<a href="index.php?r=categories/show&id=54" id="yt2">Thriller</a></li>
<li>
<a href="index.php?r=categories/show&id=55" id="yt3">Sci-Fi</a></li>
<li>
<a href="index.php?r=categories/show&id=56" id="yt4">Childern's</a></li>
</ul>
// all the below stuff is written to the DOM by the ajaxLink() function using Javascript:
<script type="text/javascript">
/*<![CDATA[*/
jQuery(document).ready(function() {
jQuery('#yt0').click(function(){jQuery.ajax({'url':'/suomusic/index.php?r=categories/show&id=52','cache':false,'success':function(html){jQuery("#content").html(html)}});return false;});
jQuery('#yt1').click(function(){jQuery.ajax({'url':'/suomusic/index.php?r=categories/show&id=53','cache':false,'success':function(html){jQuery("#content").html(html)}});return false;});
jQuery('#yt2').click(function(){jQuery.ajax({'url':'/suomusic/index.php?r=categories/show&id=54','cache':false,'success':function(html){jQuery("#content").html(html)}});return false;});
jQuery('#yt3').click(function(){jQuery.ajax({'url':'/suomusic/index.php?r=categories/show&id=55','cache':false,'success':function(html){jQuery("#content").html(html)}});return false;});
jQuery('#yt4').click(function(){jQuery.ajax({'url':'/suomusic/index.php?r=categories/show&id=56','cache':false,'success':function(html){jQuery("#content").html(html)}});return false;});
});
/*]]>*/
</script>
- Regular Ajax link:
<ul class="categoryList">
<li>
<a href="index.php?r=categories/show&id=52" onclick="jQuery.ajax({'url':'index.php?r=categories/show&id=52','cache':false,'success':function(html){jQuery('#content').html(html)}});return false;">Romance</a>
</li>
<li>
<a href="index.php?r=categories/show&id=53" onclick="jQuery.ajax({'url':'index.php?r=categories/show&id=53','cache':false,'success':function(html){jQuery('#content').html(html)}});return false;">Mystery</a>
</li>
<li>
<a href="index.php?r=categories/show&id=54" onclick="jQuery.ajax({'url':'index.php?r=categories/show&id=54','cache':false,'success':function(html){jQuery('#content').html(html)}});return false;">Thriller</a>
</li>
<li>
<a href="index.php?r=categories/show&id=55" onclick="jQuery.ajax({'url':'index.php?r=categories/show&id=55','cache':false,'success':function(html){jQuery('#content').html(html)}});return false;">Sci-Fi</a>
</li>
<li>
<a href="index.php?r=categories/show&id=56" onclick="jQuery.ajax({'url':'index.php?r=categories/show&id=56','cache':false,'success':function(html){jQuery('#content').html(html)}});return false;">Children's</a>
</li>
</ul>
I am certain as to which I would would prefer to be my page source, since I often create fully Ajaxed websites and all that DOM writing, which would be monumental and which relies on the client memory and processor to output, would be a massive performance hit 
There is absolutely no technical merit to the ajaxLink() method. It does not separate logic, there is no less coding, it bloats the output source code, it adversely affects performance and relies on the client machine for processing and most importantly, is inherently buggy.
The problems with using ajaxLink() within Ajax loaded pages are well documented and unresolved and introduce even more problems such as those encountered by Cooper.