簡體   English   中英

如何使用jquery ajax顯示從數據庫到圖像src的圖像文件路徑

[英]how to display image filepath from database to image src using jquery ajax

當我單擊它時,我有一個btn-edit模態窗口顯示出來,然后我使用ajax發出請求,然后在html的輸入標簽上顯示我的請求。

$('#btn-edit_profile').click(function(){
 $('#modal-update_profile').modal({backdrop: 'static', keyboard: true});


    $.ajax({
            url:'../ajax/getprofile.php',
            type:'POST',
            data:{userid:user},
            dataType:'JSON',
            success: function(result){
            $('#profile_image').attr('src','data:image/png;base64,'+result.profile_image+'"/>');    
            $('#users_firstname').val(result.users_firstname);
            }
    });
}); 

但是我在這里遇到的問題是,在輸入標簽上它可以正常工作,但在圖像src上卻不能..由於某種原因,我在控制台上收到此錯誤。data data:image/png;base64,../img/doc/ui-sam.jpg net::ERR_INVALID_URL

什么是顯示src的文件路徑的正確方法?

我數據庫中圖片的文件路徑為../img/doc/ui-sam.jpg ,返回JSON profile_image: "../assets/img/doctors/ui-sam.jpg"

這是我希望顯示數據庫中的圖像的地方<img class="img-responsive" id="profile_image" name="profile_image" src=""/>

$('#btn-edit_profile').click(function(){
 $('#modal-update_profile').modal({backdrop: 'static', keyboard: true});


    $.ajax({
            url:'../ajax/getprofile.php',
            type:'POST',
            data:{userid:user},
            dataType:'JSON',
            success: function(result){
            $('#profile_image').attr('src',result.profile_image);    
            $('#users_firstname').val(result.users_firstname);
            }
    });
}); 

您將返回圖像的URL,這就是src屬性所需的全部。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM