2013-04-18 49 views
2

我有我的php,下面是我的html代碼。我試着去填充PHP代碼列表視圖,但失敗了,任何想法如何將php結果填充到jquery移動列表視圖中

<? 
require_once("../backend/functions.php"); 
dbconn(); 

$id = $CURUSER["id"]; 
$e = date("Y/m/d");    
$a = SQL_Query_exec("SELECT enddate FROM cal_events WHERE userid = '$id' 
         AND enddate > '$e' ORDER BY enddate ASC"); 

if (mysql_num_rows($a) == 0) { 
?> 
    <script> 
    alert("You have no active events to deal with"); 
    window.location ='index.html'; 
    </script> 

<? 
}else{ 

    $data = array(); 
    while($rowa = mysql_fetch_array($a)) 
    { 
    $data[] = $rowa; 
    } 
    echo json_encode($data); 
} 

現在我的HTML是不正確的,這是我需要在正確的方向

HTML

<script type="text/javascript"> 
    $(document).on("pagebeforeshow", "#index4", function() { 
    $(function(){ 
     var items=""; 
     $.getJSON("check-events.php",function(data){ 
     $.each(data,function(index,item) 
     { 
      items+="<li>"+item.enddate+"</li>"; 
     }); 
     $("#contacts").html(items); 
     $("#contacts").trigger("change"); 
     }); 
    }); 
    }); 
</script> 
<ul id="contacts" data-role="listview" data-divider-theme="b" data-inset="true"> 
</ul> 
一點幫助

我哪裏錯了?它填充列表,但沒有jQuery的元素

+0

你是什麼意思的jQuery元素? – asifrc

+0

它只是一個沒有jQuery的移動主題位 –

+0

mramm888的答案應該工作。但我強烈建議你從functions.php中刪除所有javascript,並用另一個json響應來替換它,否則它會做奇怪的事情。 – asifrc

回答

3

您必須刷新列表視圖不觸發:

$("#contacts").listview("refresh"); 
+0

謝謝,有一次我確實有過這個,但我讓他們都在同時。 Thankyou的答案;) –

4

你的PHP文件返回JSON,但你應該添加

header('Content-Type: application/json'); 

呼應的JSON之前

+0

我會加上這個謝謝 –

+0

不客氣。 – ElSinus

相關問題