admin管理员组文章数量:1122832
I have search results which will show load more button but when search for new result it is started from the already incremented value how to avoid this
jQuery(document).on("click", '#load-more', function(event) {
//jQuery("#more_posts").css("display",'none'); // Disable the button, temp.
var get_query_value = jQuery('body').find('#s').val();
jQuery("#loadingImage").show();
load_main_posts(get_query_value);
});
var ppp = 3; // Post per page
var pageNumbers = 1;
function load_main_posts(get_query_value){
var $latest_content = jQuery('#latest_content');
pageNumbers++;
var str1 = 'pageNumber=' + pageNumbers + '&ppp=' + ppp+ '&action=load_search_results'+
'&query='+get_query_value ;
//console.log(str1) ;
jQuery.ajax({
type: "POST",
dataType: "json",
url : myAjax.ajaxurl,
data : str1,
success: function(response){
console.log(pageNumbers);
console.log(response.length);
if (pageNumbers >= response.max) {
console.log("teststa");
jQuery("#load-more").hide();
}
jQuery("#ajax-posts").append(response.html);
jQuery("#loadingImage").hide();
},
error : function(jqXHR, textStatus, errorThrown) {
console.log("error");
}
});
return false;
}
I have search results which will show load more button but when search for new result it is started from the already incremented value how to avoid this
jQuery(document).on("click", '#load-more', function(event) {
//jQuery("#more_posts").css("display",'none'); // Disable the button, temp.
var get_query_value = jQuery('body').find('#s').val();
jQuery("#loadingImage").show();
load_main_posts(get_query_value);
});
var ppp = 3; // Post per page
var pageNumbers = 1;
function load_main_posts(get_query_value){
var $latest_content = jQuery('#latest_content');
pageNumbers++;
var str1 = 'pageNumber=' + pageNumbers + '&ppp=' + ppp+ '&action=load_search_results'+
'&query='+get_query_value ;
//console.log(str1) ;
jQuery.ajax({
type: "POST",
dataType: "json",
url : myAjax.ajaxurl,
data : str1,
success: function(response){
console.log(pageNumbers);
console.log(response.length);
if (pageNumbers >= response.max) {
console.log("teststa");
jQuery("#load-more").hide();
}
jQuery("#ajax-posts").append(response.html);
jQuery("#loadingImage").hide();
},
error : function(jqXHR, textStatus, errorThrown) {
console.log("error");
}
});
return false;
}
Share Improve this question asked Apr 12, 2024 at 5:11 mikemike 1 2- Can you explain more please. – Aftab Commented Apr 12, 2024 at 8:53
- Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Bot Commented Apr 25, 2024 at 1:22
1 Answer
Reset to default 0It seems you have hardcoded your pageNumber as 1 always.
var pageNumbers = 1;
So every time you click on "Load More" this value will be incrementing even if you are searching for new term.
My approach would be to store the pageNumber value in "Load More" button.
<button data-pageNumber="1" id="load-more">Load More</button>
And when you click on load more just update the data-pageNumber to +1.
And if you do a new search then update the value back to "1".
本文标签: Loadmore search results not showing new results
版权声明:本文标题:Loadmore search results not showing new results? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736310509a1934402.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论