0

我必须通过ajax调用在jquery mobile中的模板中附加数据,并且我正在使用以下库和listview函数来引用现有的listview(“refresh”)函数,但它显示js错误,即listview不是函数,而函数存在于下面的库:

<script src="https://d10ajoocuyu32n.cloudfront.net/jquery-1.9.1.min.js"></script>
<script src="https://d10ajoocuyu32n.cloudfront.net/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
<script src="https://d10ajoocuyu32n.cloudfront.net/codiqa.ext.js"></script>

这是我用过的

jQuery(document).ready(function () {
 jQuery('.pagination_ajax_request').click(function () {
     jQuery.ajax({
         type: 'POST',
         url: this.href,
         dataType: 'html',
         data: 'pagination_ajax_request=1',
         success: function (response) {

             // check if <div id="pagination"><div> exist, means ajax resopnse from post listing page other wise ajax resopnse from topic listing page
             if (jQuery("#pagination").length) {
                 jQuery("#pagination").append(response);
             } else {
                 jQuery("#topic_list").append(response);
                 jQuery("#topic_list").listview("refresh");
             }
             if (ajax_pagination_data['current_page'] != ajax_pagination_data['total_pages'] && ajax_pagination_data['current_page'] != '0') {
                 //update "Load More Topics" OR "Load More Posts" link href value
                 var href = jQuery(".pagination_ajax_request").attr('href');
                 jQuery(".pagination_ajax_request").attr('href', href.replace(/&?trail=\d+/, '&trail=' + ajax_pagination_data['trail']));
             } else {
                 //hide "Load More Topics" OR "Load More Posts" if No topic OR post
                 jQuery(".pagination_ajax_request").hide();
             }
         },
         error: function (xhr, textStatus, errorThrown) {
             alert('An error occurred while processing your request.\n' + textStatus + ': ' + errorThrown);
         }
     });
     return false;
  });
});
4

2 回答 2

1

您从服务器获得的数据在这里很重要。在列表视图中添加动态内容是示例

我想你在添加 li 时错过了一些元素或东西

 $('<li>').append('<a href="#">Mercedes</a>').appendTo('#test-listview');

或者你可以试试

var UI = $('#listViewID');
for(x in data){
   UI.append(data);
}
$('#listViewID').listview("refresh");
于 2013-08-01T15:08:13.430 回答
0

我遇到了同样的问题。我恢复到 jquery v1.8.3 并解决了这个问题。

您可以在这里尝试 1.8.3 和 1.3.1 的组合:http: //jsfiddle.net/dPwzE/

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css"/>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script
<script type="text/javascript" src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
于 2013-08-05T02:00:40.407 回答