使用ajax在网页上显示FileResponse(fastapi)返回的图像

2024-09-30 16:37:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用ajax向我的api发出GET请求。api返回一个图像和一些其他信息(我想发送的信息)。我使用fastapi的FileResponse函数发送图像。我没有得到的是如何在wbepage上显示从api发送的图像。我正在寻找用于显示通过FileResponse发送的图像的javascript。 api中的返回语句:

return {'img_src':FileResponse(Path_to_the_image), 'Tables':output_dic}

html端代码:

$.ajax({ 
                    url: URL for api,   
                    type: 'get', 
                    dataType : "json",
                    contentType: "application/json; charset=utf-8",
                    success: function(response){
            I am using the contents of response here
 }

我能够成功地使用与图像一起返回的“表”的内容,但我不知道如何显示发送的图像。谁能告诉我怎么做。 先谢谢你


Tags: the函数图像api信息jsongetreturn