2014-07-18 21 views
0

我正在通過GET響應消息從服務器(php文件)中加載可摺疊的列表視圖。然而,jQuery的格式不被應用到添加的HTML儘管刷新了jQuery元素jQuery格式不適用於Ajax數據,儘管referesh

我的頁面在這裏:http://i.cs.hku.hk/~hsbashir/Project_Work/events/events.html

HTML代碼(僅適用於相關的代碼)

<script> 
lastRecord=0; 

    function loadEvents(){ 

     $('#sample').html('hello'); 
     $.get(
     "eventquery.php?lastRecord="+lastRecord, 
     function(data) { 
      $('#loadCollapsible').append(data) 
      .listview('refresh'); 
      }); 

    } 
</script> 
</head> 
<body style="background-color : #e9e9e9;" onload="loadEvents()"> 

<div data-iconpos="none" data-role="collapsibleset" data-theme="a" data-content-theme="a"> 

<div data-role="collapsible" data-collapsed="false"> 
    <h2><img src="today_calendar.png" style="height: 60px; vertical-align:middle;"> Today's Events </h2> 
    <div id="loadCollapsible"> 
    <!-- Load from php --> 
    </div> 
</div> 

PHP代碼(僅限相關代碼)

while ($row = mysql_fetch_array($result)){ 

     print '<div data-role="collapsible" data-collapsed="false">'; 

     print '<h5>'.$row['Title'].'<h5>'; 
     print ' <ul data-role="listview">'; 
     print '<li><a href="#">'; 
     print '<table><tr><td>Date</td>'; 
     print '<td style="padding: 10px;">'.$row['Date'].'</td>'; 
     print '</tr><tr>'; 
     print '<td> Time </td>'; 
     print '<td style="padding: 10px;">'.$row['Time_Duration'].'</td>'; 
     print '</tr><tr>'; 
     print '<td> Venue </td>'; 
     print '<td style="padding: 10px;">'.$row['Venue'].'</td>'; 
     print '</tr></table></a></li>'; 
     print '<li style="background-color: #CADECC;">'; 
     print '<button class="ui-btn ui-shadow ui-corner-all ui-btn-icon-left ui-icon-calendar" style="width: 170px; float: right; position: relative;">Add to calendar</button>'; 
     print '</li></ul>'; 

     print '</div>'; 
    } 
+2

嘗試創建而不是刷新 – cameronjonesweb

回答

0

感謝@ user1672694。此代碼的工作原理是在HTML改變功能loadEvents()

function loadEvents(){ 

    $('#sample').html('hello'); 
    $.get(
    "eventquery.php?lastRecord="+lastRecord, 
    function(data) { 
     $('#loadCollapsible').append(data) 
     .trigger('create')  
     .listview('refresh'); 
     });   
} 
1

jQuery Mobile的ListView控件必須首先調用刷新方法之前被初始化。

因爲您使用ajax加載列表,它不會自動初始化。試試這個:

function loadEvents(){ 

     $('#sample').html('hello'); 
     $.get(
     "eventquery.php?lastRecord="+lastRecord, 
     function(data) { 
      $('#loadCollapsible').append(data); 
      $('#loadCollapsible ul').listview().listview('refresh'); 
      }); 

    } 
相關問題