Skip to content Skip to sidebar Skip to footer

Get Images From Mysql With Php Jquery Ajax And Display Them In Html Page Inside Divs

I am editing my question after in depth searching about my problem basically my website is a fashion display website it displays shoes cloths and bags etc now its obvious that i wi

Solution 1:

Here's the jquery code that should work:

<script>
$(function () {

  $(document).on('click', 'div.prodcls img', function (e) {
    e.preventDefault();
    window.open($(this).attr('src').replace('/thumbnails', ''), '');
  });

});
</script>

And some css for good measure:

<style>div.prodclsimg:hover {
  cursor: pointer;
}
</style>

Here's a working fiddle: http://jsfiddle.net/DenGp/

Solution 2:

Css:

#imagePopup{ float:left; z-index:10; position: absolute;} 

Add some positioning

HTML:

<div id="prodtwoid"class="prodcls">
<imgsrc="images/thumbnail/zara/2.png"alt="ZARA"/>
</div>

<divid="prodthreeid"class="prodcls"><imgsrc="images/thumbnail/puma/1.png"alt="PUMA"/></div><divid="prodfourid"class="prodcls"><imgsrc="images/thumbnail/hermes/1.png"alt="HERMES"/></div>//This is you popup div<divid='imagePopup'style='display:none'></div>

JS:

$('.prodcls').click(function(){
   var src = $(this).attr('src').replace('/thumbnail', '');
    $("#imagePopup").html("<img src='"+src+"'/>")
    $("#imagePopup").toggle();
});

Updated answer:

HTML: (give every image a link):

<ahref='showImage.php?img=path/of/image.jpg'><imgsrc='path/of/thumb.jpg'/></a>

showImage.php:

$sImagePath = $_GET['img'];
echo"<div class='imgDiv'>";
echo"<img src='$sImagePath' />";
echo"</div>;

Solution 3:

You can open actual image in new browser tab without jQuery:

For Example:

<divid="prodoneid"class="prodcls"><ahref='images/zara1.png'target='_blank'><imgsrc="images/thumbnail/zara/1.png"alt="ZARA"/></a></div>

Solution 4:

Perhaps a lightbox is what you really need? take a look at this library: http://www.huddletogether.com/projects/lightbox2/

Solution 5:

You have an error in your AJAX code (your forgo to include the actual var:

$(document).ready(function() {
    $('ul.sub_menu a').click(function() {
        var txt = $(this).text();  
            $.ajax({
            type: 'POST',
            url: 'thegamer.php',
            data: {'txt':txt}  //added :txt here
            });
    });
});

Now in PHP:

$txt = $_GET['txt'];
//Now lookup $txtin you msyql db
//And echo the result, so JS can read it.

Post a Comment for "Get Images From Mysql With Php Jquery Ajax And Display Them In Html Page Inside Divs"