如何将php结果填充到jquery移动列表视图中


How do you populate php results into a jquery mobile listview

我有我的php下面与我的html代码。我试图填充一个列表视图与php代码,但失败,任何想法

<?
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元素

你的PHP文件返回json但是你应该添加

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

返回json

必须刷新listview以避免触发:

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