cakephp-2.0带有jshelper的最简单ajax链接
我想创建CakePHP2.0中最基本的ajax链接 在index.ctp中,我有cakephp-2.0带有jshelper的最简单ajax链接,php,cakephp,cakephp-2.0,cakephp-helper,Php,Cakephp,Cakephp 2.0,Cakephp Helper,我想创建CakePHP2.0中最基本的ajax链接 在index.ctp中,我有 <?php echo $this->Js->link('myLink', array('controller'=>'technologies', 'action'=>'view'), array('update'=>'#success')); ?> <div id="success"></div> public function view(){
<?php
echo $this->Js->link('myLink', array('controller'=>'technologies', 'action'=>'view'), array('update'=>'#success'));
?>
<div id="success"></div>
public function view(){
$this->set('msg', 'message');
$this->render('view', 'ajax');
}
<?php echo $msg;?>
在视图中.ctp我有
<?php
echo $this->Js->link('myLink', array('controller'=>'technologies', 'action'=>'view'), array('update'=>'#success'));
?>
<div id="success"></div>
public function view(){
$this->set('msg', 'message');
$this->render('view', 'ajax');
}
<?php echo $msg;?>
它不在success div中设置视图,而是导航到页面以显示消息
非常感谢任何帮助 试试
$this->autoRender=FALSE代码>确保在控制器中设置$components=array('RequestHandler')我想您可能需要这样做:
echo $this->Js->writeBuffer();
echo $this->Js->writeBuffer();
某处-例如在$this->Js->link
调用的正下方
希望有帮助 默认情况下,脚本是缓存的,您必须显式打印缓存。要在每页末尾执行此操作,请在结尾标记前包含此行:
echo $this->Js->writeBuffer(); // Write cached scripts
我在Layouts文件夹中default.ctp的末尾使用了它,因此,总的来说,代码看起来是这样的-它对我很有用(CakePHP 2.2.4):
index.ctp:
<?php
echo $this->Js->link('myLink', array('controller'=>'technologies', 'action'=>'view'), array('update'=>'#success'));
?>
<div id="success"></div>
echo $this->Js->writeBuffer();
echo$this->Js->writeBuffer();
非常感谢,这帮助我了解了2.0及以上版本的工作原理:)我只是说:
echo $this->Js->writeBuffer();
echo $this->Js->writeBuffer();
它对我有用,希望我能对你有用。听起来像是javascript错误。。。。