2017-07-07 86 views

回答

0

只是echo来自数据库的img源代码。

<?php 
    if(isset($_POST['profile_id'])){ 
    var uid=$_POST['profile_id']; 
    $result->query("SELECT profile FROM user WHERE uid=$uid"); 
    $row=$result->fetch_array(); 
    die(json_encode($row)); 
    } 
?> 

HTML:

<a href="#" class="pop"> 
    <img src="" style="width: 400px; height: 264px;"> 
</a> 

jQuery的部分:

$.post("ajax.php",{profile_id:1},function(response){ 
    if(response){ 
    var profileImg=JSON.parse(response); 
     profileImg=profileImg[0].profile; 
     $('.pop img').attr('src','http://example.com/image/'+profileImg); 
     $('.pop').modal('show'); 
    } 
}); 
+0

萨拉特我知道PHP的一部分。我想知道如何使用jquery和bootstrap以模态显示图像。 – JayV

+0

@JayV请看到更新的答案 –