PHP jQuery移动列表视图链接返回“未定义”

时间:2011-11-28 08:46:40

标签: php jquery mobile

我第一次使用jQuery Mobile Framework。我已经从站点复制了示例代码以获取列表视图。根据文档,它应该进行AJAX调用,然后更新DOM。

当我点击链接时,会正确弹出ajax加载图标。然后页面重新加载,其中唯一的单词是“undefined”。

我正在使用CakePHP,它已经拉入了我的移动布局。如果我重新加载页面,我会得到正确的页面视图。

有人可以告知这条“未定义”消息的来源以及如何使其发挥作用吗?

谢谢,  安迪

编辑:包含代码

// mobile layout 
<div data-role="page" class="type-interior">            
    <div class="content-primary">
            <p><?php echo $content_for_layout; ?></p>
    </div><!-- /content -->    
</div><!-- /page -->


// gallery view
<div data-role="header">
    <h1>My heading</h1>
</div><!-- /header -->
<ul data-role="listview" data-filter="true">
<li><?php echo $this->Html->link('Gauteng',array('controller'=>'regions','action'=>'gallery',4)); ?></li>
    <li><?php echo $this->Html->link('Western Cape',array('controller'=>'regions','action'=>'gallery',1)); ?></li>
    <li><?php echo $this->Html->link('Eastern Cape',array('controller'=>'regions','action'=>'gallery',2)); ?></li>
    <li><?php echo $this->Html->link('Northern Cape',array('controller'=>'regions','action'=>'gallery',9)); ?></li>
    <li><?php echo $this->Html->link('Free State',array('controller'=>'regions','action'=>'gallery',3)); ?></li>
    <li><?php echo $this->Html->link('Mpumalanga',array('controller'=>'regions','action'=>'gallery',7)); ?></li>
    <li><?php echo $this->Html->link('Kwa-Zulu Natal',array('controller'=>'regions','action'=>'gallery',5)); ?></li>
    <li><?php echo $this->Html->link('North West',array('controller'=>'regions','action'=>'gallery',8)); ?></li>
    <li><?php echo $this->Html->link('Limpopo',array('controller'=>'regions','action'=>'gallery',6)); ?></li>
</ul>

点击其中任何一个会导致页面显示“未定义”。它具有移动布局,但没有读取正确的视图文件。

编辑: 谷歌广泛发现了一个类似的问题answered here on stackoverflow但是当我尝试在beforeRender方法中更改布局时,ajax永远不会完成。我用firebug跟踪网络流量,可以看到http get请求正在成功完成并返回正确的页面信息(整个页面)。但是,JQM没有更新视图。

1 个答案:

答案 0 :(得分:0)

我又遇到了这个问题,并认为注意这里的解决方案可能有助于人们。第二次遇到问题是因为我使用CakePHP并且需要在我的视图文件的顶部包含正确的div标签,以便AJAX调用可以检测传入的内容。