[英]How to solve jQuery ajax load more issue?
I am using load more functionality in my application using jQuery ajax. 我正在使用jQuery ajax在应用程序中使用加载更多功能。 This is my ajax code: 这是我的ajax代码:
$(document).ready(function() {
$(document).on('click','.show_more', function(e) {
e.preventDefault();
var ID = $(this).attr('id');
//$('.show_more').hide();
//$('.loding').show();
alert(ID)
$.ajax({
type:'POST',
url:'ajax_load_more.php',
data:{"id" : ID},
success:function(html){
$('#show_more_main'+ ID).remove();
$('.showmorediv').append(html);
}
});
e.preventDefault();
});
For testing i put alert to display id it working perfectly. 为了进行测试,我将警报显示为id来正常工作。 But ajax code is not working.there is no error and no console log found. 但是ajax代码不起作用,没有错误,也没有找到控制台日志。 i double check ajax_load_more.php page it working perfectly according to alerted id. 我仔细检查了ajax_load_more.php页面,它根据警报ID正常工作。
Here is my php code 这是我的PHP代码
if(isset($_POST["id"]) && !empty($_POST["id"]))
{
$queryAll = $conn->query("SELECT COUNT(*) as num_rows FROM product WHERE id < ".$_POST['id']." ORDER BY id DESC");
$row = $queryAll->fetch_array();
$allRows = $row['num_rows'];
$showLimit = 3;
$query2 = $conn->query("SELECT * FROM product WHERE id < ".$_POST['id']." ORDER BY id DESC LIMIT ".$showLimit);
$rowCount = $query2->num_rows;
if($rowCount > 0){
while($row_p = $query2->fetch_array()){
$loadmoreid = $row_p["id"]; ?>
<div class="col-md-4 col-sm-6 col-xs-12 mar-bot showmorediv">
<!-- single-product-start -->
<div class="single-product">
<div class="single-product-img">
<a href="product-details/<?=preg_replace('!\s+!', '-',preg_replace("/[^A-Za-z0-9 \s+]/",' ',$row_p[4]));?>-<?=$row_p[0];?>">
<img src="<?=$row_p[13];?>" alt="<?=$row_p[3];?>"/>
</a>
<span class="sale-box">
<span class="sale">-<?php echo $offprice=round((($row_p[5]-$row_p[6])*100)/$row_p[5]); ?>%</span>
</span>
</div>
<div class="single-product-content">
<div class="product-title">
<h5>
<a href="product-details/<?=preg_replace('!\s+!', '-',preg_replace("/[^A-Za-z0-9 \s+]/",' ',$row_p[4]));?>-<?=$row_p[0];?>"><?=$row_p[3];?></a>
</h5>
</div>
<div class="price-box">
<span class="price">Rs.<?=$row_p[6];?></span>
<span class="old-price">Rs.<?=$row_p[5];?></span>
</div>
<div class="product-action">
<button class="btn btn-default add-cart" data-id="<?=$row_p[0];?>" data-name="<?=$row_p[3];?>" data-summary="<?=$row_p[3];?>" data-price="<?=$row_p[6];?>" data-quantity="1" data-image="<?=$row_p[13];?>">Add to cart</button>
</div>
</div>
</div>
</div>
<?php
}
if($allRows > $showLimit)
{
?>
<div class="show_more_main" id="show_more_main<?php echo $loadmoreid; ?>">
<span id="<?php echo $loadmoreid; ?>" class="show_more btn btn-primary" title="Load more posts btn btn-primary">More</span>
<span class="loding" style="display: none;"><span class="loding_txt">Loading…</span></span>
</div>
<?php }
}
}
?>
You can get the unknown error by using jquery ajax error function
as like this 您可以像这样使用jquery ajax error function
来获取未知错误
https://stackoverflow.com/a/8918298/7419418 https://stackoverflow.com/a/8918298/7419418
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.