我觉得有必要让浏览器后退按钮工作,以及允许用户为他们看到的内容添加书签。
我在 Zend 路线上不是多才多艺,但我暂时无法改变这一点。
这是我正在使用的 ajax 实现方法:
class TestController extends Zend_Controller_Action {
public function init()
{
/* Initialize action controller here */
if ($this->getRequest()->isXMLHttpRequest()) {
$this->_helper->layout()->setLayout('blank');
$logger = $this->getInvokeArg('bootstrap')->getResource('Log');
$logger->debug('AJAX Call');
}
}
public function indexAction()
{
// render the default page
}
public function somethingelseAction()
{
// do something else render something.
}
}
让我的初始视图呈现与目标 div 以及一些链接...这是我的 index.phtml:
<h1>Tests...</h1>
<a class="ajaxloader"
href="<?php echo $this->url(array('controller'=> 'test', 'action' => 'speed'), null, true);?>">Speed</a>
<a class="ajaxloader"
href="<?php echo $this->url(array('controller'=> 'test', 'action' => 'somethingelse'), null, true);?>">Something Else</a>
<div id="testresults">
<h1>Default stuff to show.</h1>
</div>
一些 jQuery 代码附加到这些“ajaxloader”链接并将结果定位到“testresults”div。
$(function() {
$('.ajaxloader').click(function(event) {
var target = $(this).attr('href');
window.location.hash = target;
$('#testresults').fadeOut('slow', function() {
// complete fadeout, load new content while it's hiding!
$.ajax( {
url : target,
success : function(data) {
$('#testresults').html(data);
$('#testresults').fadeIn();
}
});
});
return false;
})
});
如何在这里实现深层链接?
非常感谢,MEM
PS - 此实现的良好功劳归功于 Darryl E. Clarke。我可以接受坏人。