jQuery格式不应用于ajax数据,尽管刷新
jQuery formatting not applying to ajax data despite referesh
我正在通过GET响应消息从服务器(php文件)加载一个可折叠的列表视图。但是,尽管刷新了jQuery元素
,但jQuery格式并没有应用到添加的HTML中。我的主页在这里: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>';
}
jQuery Mobile listview必须在调用刷新方法之前先初始化。
因为你是用ajax加载列表,所以它不会自动初始化。试试这个:
function loadEvents(){
$('#sample').html( 'hello' );
$.get(
"eventquery.php?lastRecord="+lastRecord,
function( data ) {
$('#loadCollapsible').append( data );
$('#loadCollapsible ul').listview().listview( 'refresh' );
});
}
感谢@user1672694。这段代码通过改变HTML中的loadEvents()
函数来工作:
function loadEvents(){
$('#sample').html( 'hello' );
$.get(
"eventquery.php?lastRecord="+lastRecord,
function( data ) {
$('#loadCollapsible').append( data )
.trigger( 'create' )
.listview( 'refresh' );
});
}
相关文章:
- JQGrid使用服务器编辑后的更新数据刷新数据
- 如何刷新数据表列数据
- vue.js使用定时器自动重新加载/刷新数据
- 数据库更新后刷新数据表
- 插入数据并用新数据刷新数据网格后,关闭弹出窗口
- 如何使用复选框jQuery取消选中并刷新数据
- 刷新数据时,下拉列表以 ng-重复形式关闭
- 仅当使用 AngularJS 从服务器中找到新数据时,才自动刷新数据
- 从 json 接收的 jQuery 刷新数据
- 主干:更改集合后刷新数据表
- 谷歌折线图,刷新数据表
- 在角度.js中编辑后立即刷新数据表
- ajax json天气自动刷新数据
- 单选按钮不刷新数据
- 在设置时间后刷新数据并调用backingbean方法
- 刷新数据表时出错-无法重新初始化数据表
- 勾选复选框全选,并刷新数据表
- 如何在调用页事件后刷新数据表
- 我如何使一个html页面可打印而无需重新加载/刷新数据
- NVD3 -如何刷新数据功能,以产生新的数据点击