通过ajax cakephp 2.x加载视图
我想通过ajax在我的视图上加载一个项目列表,这是我在lst.cpt上的代码通过ajax cakephp 2.x加载视图,ajax,cakephp,cakephp-2.3,Ajax,Cakephp,Cakephp 2.3,我想通过ajax在我的视图上加载一个项目列表,这是我在lst.cpt上的代码 <div id='benpane' class='clearfix'> <script type="text/javascript"> <?php echo $ajax->remoteFunction(array( 'url'=>array('controller'=>'benefits', 'action'=>'display'), 'up
<div id='benpane' class='clearfix'>
<script type="text/javascript">
<?php echo $ajax->remoteFunction(array(
'url'=>array('controller'=>'benefits', 'action'=>'display'),
'update'=>'benpane',
'indicator'=>'benIndicator'
)); ?>
</script>
</div>
当我试图打开视图时,我得到了错误
Error: Call to a member function remoteFunction() on a non-object
File: /var/www/hassportal/app/View/Benefits/lst.ctp
Line: 14
我可能做错了什么?除了Ajax助手已被弃用(和/或您可能没有使用cakephp 2.x)之外,您似乎在调用错误的操作:
'action'=>'display'
应该是:
'action'=>'lst'
此外,我会将代码移到应该使用来自该操作的数据进行更新的DIV之外
$this->Ajax->remoteFunction
暗示
$ajax->remoteFunction
例:-
您不应该改用JSHelper吗?是什么取代了ajax helper?如何使用新版本获得相同的结果?您可以使用。例如:JsHelper::request或者旧的helper的。
$ajax->remoteFunction
<?php echo $this->Ajax->remoteFunction(array(
'url'=>array('controller'=>'benefits', 'action'=>'display'),
'update'=>'benpane',
'indicator'=>'benIndicator'
)); ?>