【发布时间】:2013-08-01 21:10:01
【问题描述】:
我必须通过 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;
});
});
【问题讨论】:
-
我们需要先查看您的代码,然后我们才能为您提供帮助。
-
确保在加载完所有内容后调用它,即。 e.里面 $(function(){ .. }); (或之后)
-
响应中返回了什么? (成功:函数(响应))
-
我们以
- 标记的形式获取数据,所需数据必须附加到现有的
- 中。
- 标记的形式获取数据,所需数据必须附加到现有的
-
#topic-list是div还是ul?