使用javascript从sqlserver检索图像 [英] Retriving images from sqlserver using javascript

查看:59
本文介绍了使用javascript从sqlserver检索图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!


我已经使用C#从数据库中检索了图像,但是如何在.aspx页面的javascript幻灯片中显示它们呢?

hello all !!


i have retreived images from database using c# but how can i show them in a javascript slideshow in my .aspx page?

推荐答案

客户端和JS代码不有权访问数据库(希望很明显).因此,您需要提供一个服务器脚本来从数据库加载图像并将其作为HTTP文件"返回,然后让JavaScript加载该URL.

我实际上并没有在ASPX中完成此操作,仅使用了伪代码,但是您需要做的是类似
The client and JS code don''t have access to the database (hopefully that''s obvious). So you need to provide a server script to load an image from the database and return it as a HTTP ''file'', and then have the JavaScript load that URL.

I''ve not actually done this in ASPX so pseudocode only, but what you need to do is something like
int id = Page.QueryVars["id"];
DataTable dt = query("select mimetype, image from images where imageid="+id);
switch(dt.RowCount){
 case 1:
  // Return the image
  Response.MimeType = (string)dt[0]["mimetype"];
  Response.Write((byte[])dt[0]["image"]);
  break;
 case 0:
  Response.Code = 404;
  break;
 default:
  Response.Code = 500;
  Response.Write("Unexpected duplicate image id "+id);
  break;
}



然后,您可以通过检索getimage.aspx?id = 5来调用它.

希望实际上在ASPX中完成此操作的人可以对此进行补充. (我在PHP中做过类似的事情,其中​​算法是相同的,但显然代码是完全不同的.)



Then you would call it by retrieving getimage.aspx?id=5.

Hopefully someone who''s actually done this in ASPX can fill this out a bit more. (I''ve done something similar in PHP where the algorithm is the same but obviously the code is completely different.)


如果您将图像保存在文件夹中,则以下javascript可以正常工作

If u are having the images in folder then following javascript will work fine

<script type='text/javascript'

    src='http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js'>
    </script>
    <script type="text/javascript">
        var imgs = [
        'images/04.jpg',
        'images/img1.png',
        'images/user_icon.jpg'];
        var cnt = imgs.length;


(function(){ setInterval(Slider,3000); }); 函数Slider(){
(function() { setInterval(Slider, 3000); }); function Slider() {


这篇关于使用javascript从sqlserver检索图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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