'Jquery load dynamic page cache issue on php while loop,

Jquery load dynamic page cache issue on php while loop,

I have Page A and Page B

Im using Page A to load page B with different post id to get different details of post

I am loading page B inside the modal

every thing is working fine adding the jQuery load in the php loop except cache issue.

the first post id does not cahes while the rest cached show same content of the first post id

I don't know if there is way to combine the Jquery load inside the show modal. when modal pop is call the page will load without caching.

    <?php 
    foreach ($posts as $key => $result) {
    ?>
      <div hidden id="<?php echo "name_".$id;  ?>"><?php echo $name;  ?>
        
    <div id="nav_aa<?php echo $result['id'];?>" href="#" data-toggle="modal" data-target="#myModal" onClick="showModal(<?php echo $id ;  ?>)" class="view-post">
    View Post
    </div>

Jquery load code

    <script>
    $(function(){
    $("#nav_aa<?php echo $result['id'];?>").on("click", function(){
    $('#content').load('view.php?id=<?php echo $result['id'];?>', 'f=<?php echo $result['id'];?>' + (Math.random()*1000000));
    });
    });
    </script>

<? }
?>

The modal where i load page B with different post id

<div class="modal fade" id="myModals" role="dialog" >
    <div class="modal-dialog" style="position:absolute;bottom:0;margin:0;width:100%;">

      <!-- Modal content-->
      <div class="modal-content">
      <div id="name"></div>   
        <div id="content"></div>      
      </div>

    </div>
  </div>



<script>
function showModal(id)
{
$("#name").text($("#name_"+id).text());

}
</script>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source