doukanwa6872 2019-02-13 07:11
浏览 107

如何使用jquery从数据库显示图像

I have a problem with displaying an image using jquery. The image is retrieved from the database, and i want to display it using jquery. below is my codes

index.php

<?php 
require_once("db.php");

if(isset($_POST['input'])):

$id = $_POST['id'];

    $selectImage = mysqli_prepare($link,"SELECT product_image FROM products WHERE id = ? ");
    mysqli_stmt_bind_param($selectImage, "i",$id);
    mysqli_stmt_execute($selectImage);
    mysqli_stmt_bind_result($selectImage,$image);
    mysqli_stmt_fetch($selectImage);

    if($image):
      echo $image;

    else:
       echo "no image to display";
    endif;

endif;
?>

ajax.php

function imgViews(){
    $(".imageView").click(function(){
        var id = $(this).attr("id");

        $.ajax({
                url: 'class/display_image.php',
                type: 'POST',
                data: {input: 'input',
                       id:id
                   },
                success:function(data){
                 ****display image*****
                },
                dataType: "text"
        });
    });
}
imgViews();

displayHere.html

<div id="imageContainer>
    <img src="img/...."> 
</div>
  • 写回答

3条回答 默认 最新

  • doucheng7534 2019-02-13 07:16
    关注

    Try this

    success:function(data){
       $('#imageContainer').html('<img src="'+data+'"/>');
    },
    
    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计