2014-01-28 71 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