Good day. The question is what actually can not implement the article. There is a main page, it’s like a tile with an image and a short description, when you click on one of them a div (pop-up) appears and it displays more specific information of the tile you clicked on, it all works without refreshing the page. I just do not display anything at all with select.php!
index.php
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#popup1").hide(); var nav, content; nav = $('.item'); content = $('.o-post'); nav.find('a').on('click', function(e) { var href = $(this).attr('href'); history.pushState(null, null, href); $("#popup1").show(); e.preventDefault(); var data = { id: id }; var res = JSON.stringify(data); $.ajax({ url: "select.php", type: "GET", data: { data: res }, dataType: "json", success: function(response){ content.html(response); } }); }); $("#hide-post").click(function() { $("#popup1").hide(); }); }); </script> <div class="b-popup" id="popup1"> <div class="b-popup-content"> <img src="./icons/close.png" id="hide-post" style="cursor: pointer; float: right;"> <div class="o-post"></div> </div> </div> select.php
<?php include('connect.php'); $post_sql = mysqli_query($CONNECT, "SELECT * FROM images WHERE id='$_GET[id]'"); while($post_row = mysqli_fetch_array($post_sql)) { echo '<img src="./img/user_images/'.$post_row['image'].'" width="500px" id="image-post"><p>'.$post_row['description'].'</p>'; } ?>
whileyou need to make sure that something has come up from the database at all ............. besides,jsonshould return, judging by theajaxsetting, and you are pushing outhtml.... ............ And as soon as only one line was output viaechoit is sent as a response to the AJAX and everything, the remaining iterations will not work, the conclusion: you need to put everything into a variable at the beginning and only then give it as an answer - Alexey ShimanskydataType: "html",should be eitherecho json_decode(YOUR_CONTENT)...... look for what thedataTypeand what it means for example jquery.page2page.ru/index.php5/… .......... well, and other points that I described - check / execute - Alexey Shimansky