减少Ajax实施时间/延迟?

时间:2019-01-09 18:20:19

标签: php jquery ajax

我有一个页面,该页面在网格视图中通过php循环加载了多个图片,如下所示

         <?php if($rows){
         $i = 0;
         while($resImage = mysqli_fetch_array($fetchImg)){?>

        <div class="col-md-4">
        <div class="user-box">
        <h6 class="view-gallery-btn"><?php echo $resImage['image1']; ?></h6> 
        <?php $imgPath = base64_decode($_REQUEST['gallyId'])."_".$_SESSION['unique_id']; ?>
         <a href="Gallery/<?php echo $imgPath?>/<?php echo $resImage['image1']; ?>" download class="my-download-btn"><i class="fa fa-cloud-download" aria-hidden="true"></i></a>
         <a href="order.php?gallyId=<?php echo $_REQUEST['gallyId']; ?>&photo_id=<?php echo base64_encode($resImage['id']); ?>" target="_blank"><img src="poweradmin/Gallery/<?php echo $imgPath?>/<?php echo $resImage['image1']; ?>" alt="" class="img-fluid"></a>
                <ul class="new-gallery-btn add-listing-gallery">
                    <li>
                       <a href="?status=<?php echo $resImage['id']; ?>"  class="change_status redFav user-default <?php if($resImage['myfavorite_userpic']== '2'){ echo 'user-fav'; }?>"><i class="fa fa-star" aria-hidden="true"></i></a>
                    </li>
                    <li>
                       <a href="galleries_view.php?gallyId=<?php echo $_REQUEST['gallyId']; ?>&delt=<?php echo base64_encode($resImage['id']); ?>&page=<?php echo $_REQUEST['page']; ?>"><i class="fa fa-trash-o" aria-hidden="true"></i></a>
                    </li>
                    <li>
                      <input name='ids[]' type='checkbox' id='ids' class="form-check-input custom-check-box checkboxes" value="<?php echo $resImage['id']; ?>">
                    </li>
                </ul>
        </div>
        </div>
        <?php } } ?>   `

每张图片都有一个星形图标,可按如下方式调用Ajax代码

    $("a.redFav").click(function(){
    var current = this ;
    var status_id = $(this).attr('href').split('=');
    var arr = status_id[1];
    $.ajax({
        type:'post',
        url:'addUserPics.php',
        data:{arr: arr},
        success:function(msg){
            console.log("User Like Applied");
            $(current).toggleClass("user-fav");
        }
    });
    return false;
});

这将调用一个php文件,该文件将更新数据库中的相应字段,但是问题是,如果页面中有很多图像(即约100+张),并且其中一些被选中(即,单击了调用Ajax的图标)例如10个,只有其中几个被更新。每次成功统计数据都不同时,似乎是由于Ajax调用延迟或调用不完整所致。 请提出一种处理方法。

0 个答案:

没有答案