PHP jQuery 移动 ListView 链接返回 "undefined"

标签 php jquery mobile

我是第一次使用 jQuery Mobile Framework。我已经从站点复制了 ListView 的示例代码。根据文档,它应该进行 AJAX 调用,然后更新 DOM。

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

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

任何人都可以建议这个“未定义”消息的来源以及如何让它工作吗?

谢谢, 安迪

编辑:包含代码

// 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>

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

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

最佳答案

我又遇到了这个问题,并认为在这里记录解决方案可能会对人们有所帮助。我第二次遇到这个问题是因为我使用的是 CakePHP,需要在我的 View 文件顶部包含正确的 div 标签,这样 AJAX 调用才能检测传入的内容。

关于PHP jQuery 移动 ListView 链接返回 "undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8293381/

相关文章:

jquery - 将滚动条添加到 svg 容器

jquery - Twitter Bootstrap : How to close modal/popover programmatically with jQuery

php - 将网站重定向到移动网站以及从移动网站重定向到桌面网站?

javascript - 使用 SectionList React Native 滚动区域太小

php - Laravel - Controller 中的 session 获取最后设置的值

php - 多项选择并添加更多字段不起作用

php - 在 PHP 或 MySQL 上生成周五截止时间

javascript - 如何使用 JavaScript 将动态 `colspan` 放入 HTML 表格中

php - 将字段值添加到数据库

HTML5 全屏 Web 应用程序 : No browser bars