生產計算器的圖像我有我的居住web應用程序的,我要爲給用戶的上下文之外圖像的目錄。目前,我正在使用IHttpHandler來爲圖像提供服務,並使用一些JavaScript來瀏覽一組圖像(現在導航是原始的)。我遵循使用IHttpHandler爲圖像提供服務的示例,但是當我在Firefox中查看圖像時,瀏覽器掛起,當我在IE中查看時,出現「堆棧溢出在線:0」。的IHttpHandler在IE
規範了IHttpHandler
Public Class ShowImage : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) _
Implements IHttpHandler.ProcessRequest
Dim picid As String
If context.Request.QueryString("id") IsNot Nothing Then
picid = context.Request.QueryString("id")
Else
Throw New ArgumentException("No parameter specified")
End If
'' Convert Byte[] to Bitmap
context.Response.Cache.SetCacheability(HttpCacheability.NoCache)
context.Response.Cache.SetNoStore()
context.Response.Cache.SetExpires(DateTime.MinValue)
Dim newBmp As Bitmap = GetPhoto(picid)
If newBmp IsNot Nothing Then
Dim imgGraphics As Graphics = Graphics.FromImage(newBmp)
imgGraphics.DrawImageUnscaled(newBmp, 0, 0, 640, 480)
context.Response.StatusCode = 200
context.Response.ContentType = "image/jpeg"
newBmp.Save(context.Response.OutputStream, ImageFormat.Jpeg)
newBmp.Dispose()
Else
'' Return 404
context.Response.StatusCode = 404
context.Response.End()
End If
End Sub
...
Public ReadOnly Property IsReusable() As Boolean _
Implements IHttpHandler.IsReusable
Get
Return True
End Get
End Property
End Class
下面是調用了IHttpHandler的上述定義的javascript代碼:
function updateImage(){
var ddlPhotos = document.getElementById("ddlPhotos");
var selected = ddlPhotos.options[ddlPhotos.selectedIndex].value;
if(selected != -1){
// Update the image
retrievePicture(document.getElementById("propertyImage"), selected)
}
}
function retrievePicture(imgCtrl, picid)
{
imgCtrl.src = 'ShowImage.ashx?id=' + picid;
}
最後,這裏的img標籤即是 「佔位符」:
<img src="#"
alt="Property Photo"
width="640px"
height="480px"
id="propertyImage"
onload="retrievePicture(this, '<%= pictureId.value %>');"
/>
我很困惑,爲什麼的JavaScript似乎失控...
謝謝你,謝謝你。我把onload事件移動到了頁面主體(這對我來說很好),並且FF工作正常,堆棧溢出在IE中消失了。 – toddk 2009-06-24 14:22:53