2014-01-28 53 views
0

我正在学习JQuery移动(所以我很抱歉如果我的问题的答案是非常明显的)。JQuery Mobile html + php + phonegap问题

我修改了一个简单的数据列表示例,使用PHP获取JSON数据并使用它填充我的列表。我的代码如下:

<!DOCTYPE html> 
<html> 
    <head> 
     <link rel="stylesheet" href="//code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.css"> 
     <script src="//code.jquery.com/jquery-1.10.2.min.js"></script> 
     <script src="//code.jquery.com/mobile/1.4.0/jquery.mobile-1.4.0.min.js"></script> 
    </head> 
     <body> 
      <div data-role='page'> 
       <div data-role='header'> 
        testing ... testing 
       </div> 
       <?php 
        print "<br>PHP Working!<br>: " + date('d') + "<br>"; 
        $json = file_get_contents('http://*.*.*.*/mysite/app/sections'); 
        $sections = json_decode($json, true); 

        $sections = $sections['JSON']; 
       ?> 
        <ul data-role='listview'> 
       <?php 
        foreach ($sections as $key => $section) { 
       ?> 

        <li><?php print "<a href='#/{$section['tid']}'>{$section['term']}</a>" ?></li> 

       <?php 
        } 
       ?> 
         </ul> 
      </div> 
     </body> 
</html> 

在Web浏览器的输出如下图所示:

enter image description here

我的问题是,当我使用PhoneGap的生成Android移动应用,它加载但只是将我的PHP代码打印为文本。

任何人都可以告诉我,如果我正在尝试是可能的,如果是的话,我能做些什么来解决这个问题?

+0

你需要在追加项目'$(“ul”)。listview(“refresh”);'后刷新listview。 – Omar

回答

0

您必须确保已将您的config.xml中的所有外部URL列入白名单。所以你的情况,因为你从code.jquery.com加载,你应该有这样的:

<access origin="http://81.16.48.67*" /> 
<access origin="http://*.jquery.com" /> 

编辑

我想你的意思是你有PHP的服务器上,并且你正在用ajax从手机上请求。

问题是,你不能在phonegap中运行php,它只支持客户端网络技术(html/css/javascript)。所以我会建议在服务器上使用php来生成json数据。然后在你的手机上,使用jax获取该json并使用jquery将其放入html中。

+0

我的项目没有config.xml。我只在我的项目文件夹中有一个index.html。你能详细说明吗? – sisko

+0

当您创建phonegap项目时,您应该在www目录(与index.html相同的目录)中有一个config.xml。 http://docs.phonegap.com/en/3.1.0/config_ref_index.md.html#The%20config.xml%20File – aharris88

+0

我包含了一个config.xml文件,但PhoneGap生成的应用程序仍然只显示原始PHP代码 – sisko