带有数据库缩略图的图库,每个都与其他图像相关

时间:2021-10-31 00:21:06

I've searched a lot of material here and elsewhere on the web about thumbnail images linking to image gallery, but I think I'm missing something simple and hope you can help. The use chooses a set of thumbnail images to display based on a button click. I retrieve the thumbnails from a mysql database. So far, so good. On clicking a thumbnail, I want to display multiple other images related to that thumbnail and for this, I'm using a jquery script like so:

我在这里和网上其他地方搜索了很多关于链接到图库的缩略图图片,但我想我错过了一些简单的内容,希望你能提供帮助。用户根据按钮单击选择要显示的一组缩略图图像。我从mysql数据库中检索缩略图。到现在为止还挺好。在点击缩略图时,我想显示与该缩略图相关的多个其他图像,为此,我正在使用如下的jquery脚本:

    <script type="text/javascript" >
        $(document).ready(function(){
         $( "img" ).on("click",function(){
            var $thumb_name = $("img").attr("src");
            $.ajax({
                  type:"post",
                  url: "test.php",
                  data: {thumb_name:'$thumb_name'},
                  success: function( data ) {
           $( "#val" ).html(data);
           } //data
    }); //close ajax
    }); //close onclick
    }); //close document ready
    </script>

The server side php script is simply

服务器端的PHP脚本很简单

    <?php
        $thumb_name = $_POST['thumb_name'];
        echo "the clicked thumb is $thumb_name";
    ?>

I've retrieved $thumb_name from the database (I can display it/them alongside the thumbnail images). The problem is that the code above doesn't pass it to the server side as a value but rather as the string $thumb_name. I'm communicating with the php script because the string does get placed in the div named 'val'. I know how to display the further images if I can get the thumbnail image's actual name.

我从数据库中检索了$ thumb_name(我可以在缩略图图像旁边显示它/它们)。问题是上面的代码没有将它作为值传递给服务器端,而是作为字符串$ thumb_name传递给服务器端。我正在与php脚本进行通信,因为字符串确实放在名为'val'的div中。如果我能获得缩略图的实际名称,我知道如何显示更多图像。

Thanks for any help.

谢谢你的帮助。

1 个解决方案

#1


0  

You have to remove the quotes around $thumb_name:

您必须删除$ thumb_name周围的引号:

<script type="text/javascript" >
    $(document).ready(function(){
     $( "img" ).on("click",function(){
        var thumb = $(this).attr("src");
        $.ajax({
              type:"post",
              url: "test.php",
              data: {thumb_name: $thumb_name},
              success: function( data ) {
       $( "#val" ).html(data);
       } //data
     }); //close ajax
   }); //close onclick
}); //close document ready
</script>

#1


0  

You have to remove the quotes around $thumb_name:

您必须删除$ thumb_name周围的引号:

<script type="text/javascript" >
    $(document).ready(function(){
     $( "img" ).on("click",function(){
        var thumb = $(this).attr("src");
        $.ajax({
              type:"post",
              url: "test.php",
              data: {thumb_name: $thumb_name},
              success: function( data ) {
       $( "#val" ).html(data);
       } //data
     }); //close ajax
   }); //close onclick
}); //close document ready
</script>