显示存储在数据库中的图像 [英] displaying image stored in database.

查看:67
本文介绍了显示存储在数据库中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!大家好!

我面临一个问题。

如何从响应中获取数据,其中内容类型为image / jpg ore image / gif。

通常浏览器为我们做,当遇到图像标签时,它会向服务器发送图像请求,然后读取响应并按图像替换img标签。


现在我是什么想要做的如下:

step1:向服务器发送异步请求(请求图像)。


step2:服务器从数据库中读取图像,创建一个图像响应,并返回结果。


step3:在onreadystate = 4,客户端读取响应数据,创建图像元素,并向图像元素提供响应数据。


我的问题出在第3步。

据我所知,我们只能从XMLHTTPResponse对象以两种方式获得响应体,简单的文本&第二个是xml。


如何获取MIME / html&以外的MIME类型的数据text / xml。


真的很紧急,任何建议和帮助将不胜感激。


提前谢谢。

Hi! everybody!
I am facing one problem.
How to get data from response, where content type is image/jpg ore image/gif.
normally browser do it for us, when it encounters an image tag, it sends an image request to the server, then reads the response and replaces img tag by image.

Now what I want to do is as follows:
step1: send an asynchronous request(request for image) to server.

step2: server reads the image from database, creates an image response, and returns back result.

step3: at onreadystate=4, client reads response data, creates image element, and provide response data to image element.

My problem is at step3.
as far as I know we can only get response body in two ways from XMLHTTPResponse object, as simple text & second as xml.

How to get data having MIME type other than text/html & text/xml.

Its really urgent, any suggession & help will be greatly appreciated.

Thanks in advance.

推荐答案

我也试过..但失败了.... 。


试用我的代码而不使用 AJAX


[HTML]< html>

< head>

< script language = javascript>

function startPage()

{

尝试

{

if(navigator.appName.indexOf(''Explorer'')!= -1)

{

/ * var request = new ActiveXObject(''Microsoft.XMLHTTP'');

request.open(''GET'',''https://172.20.0.207/ CoalNetPROD / common / html / lov.gif'',true);

request.onreadystatechange = new function(){

alert(request.readyState);

if(request.readyState == 4)

{

if(request.status == 200)alert(request.responseText);

}

request.send(空值);

} * /


}

else {}

} catch(err){

alert(错误描述);

}

}

< / script>

< / head>

< body onload = startPage()>

< img id = img1 style =''width:170px; height: 130px''src =''https://172.20.0.207/CoalNetPROD/common/html/lov.gif''></img>

< input type = button value =" ;点击我 onclick =" document.getElementById(''img1'')。src =''https://172.20.0.207/CoalNetPROD/common/html/90003781.jpg''">

< / body>

< / html> [/ HTML]


再次欢迎
i also tried .. but failed .....

try my code without using AJAX

[HTML]<html>
<head>
<script language = javascript>
function startPage()
{
try
{
if(navigator.appName.indexOf(''Explorer'') != -1)
{
/*var request = new ActiveXObject(''Microsoft.XMLHTTP'');
request.open(''GET'',''https://172.20.0.207/CoalNetPROD/common/html/lov.gif'',true);
request.onreadystatechange = new function(){
alert(request.readyState);
if(request.readyState == 4)
{
if(request.status == 200) alert(request.responseText);
}
request.send(null);
}*/

}
else{}
}catch(err){
alert(err.description);
}
}
</script>
</head>
<body onload = startPage()>
<img id = img1 style = ''width:170px;height:130px'' src = ''https://172.20.0.207/CoalNetPROD/common/html/lov.gif''></img>
<input type = button value = " Click Me " onclick = "document.getElementById(''img1'').src = ''https://172.20.0.207/CoalNetPROD/common/html/90003781.jpg''">
</body>
</html>[/HTML]

welcome again


它可能不会正是你想要的,但这个可能会让你走上正轨。
It may not be exactly what you want, but this might put you on the right track.


非常感谢您的回复。


特别感谢acoder,因为我从他提供的链接中得到了提示。 br />
Thanks a lot for your replies.

A special thanks to acoder, as I have got a hint from the link he provided.


它可能不是你想要的,但可能会让您走上正轨。
It may not be exactly what you want, but this might put you on the right track.



提示是:

Hint is:

展开 | 选择 | Wrap < span class =codeDivider> | 行号


这篇关于显示存储在数据库中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆