2

我有我的 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 元素

4

2 回答 2

4

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

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

在回显你的 json 之前

于 2013-04-18T13:00:11.243 回答
3

您必须刷新列表视图才不会触发:

$("#contacts").listview("refresh");
于 2013-04-18T12:59:49.117 回答