从客户端代码加载图像时出现问题 [英] Problem loading an image from client side code

查看:77
本文介绍了从客户端代码加载图像时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


在我的ASP.Net页面中遇到JavaScript问题。


我使用了一些COTS,它适用于所有意图和目的,只需制作一个

jpeg文件并将其物理放置在Web服务器上的目录中。


页面加载代码隐藏,建立连接到jpeg创建

服务并获取新创建的图像的路径。


我提供的示例代码非常简单......没有火箭科学在这里。

这里是代码背后的代码:


受保护的子页面_Load(ByVal发送者作为对象,ByVal e As

System.EventArgs)处理Me.Load


Dim j As new jpegImage''删除了COTS&的代码用伪造的代码替换

用于发布目的。

Dim c As new serviceConnector''删除了COTS&的代码更换

with psuedocode用于发布目的。

Dim urlImage


c = Server.CreateObject(" Connector")''已删除代码为COTS&

替换为伪造的代码用于发布目的。

c.ServerName =" DC1" ''服务器'的名字

c.ServerPort = 5300''服务器'的端口


j = Server.CreateObject(" Jpeg")' '删除代码为COTS&

替换为psuedocode用于发布目的。

urlImage = j.GetImageAsUrl()''带有新路径的字符串

在服务器上创建jpeg文件


Me.mapImageSrc_hidden.Value = urlImage


结束子


好的......你会看到我在页面标记中使用了一个隐藏的字段。

有这么多疯狂的原因我现在就跳过但是我需要客户端加载图像...而不是服务器。下面是接下来发生的



< asp:HiddenField ID =" mapImageSrc_hidden" RUNAT = QUOT;服务器" />

< img id =" mapImage" SRC ="图像/ null.gif"的onload = QUOT;的getImage();" />


在这里'是getImage方法:


函数getImage()

{

var objHiddenImage =

document.getElementById(" mapImageSrc_hidden");

var objMapImage = document.getElementById(" mapImage");


objMapImage.src = objHiddenImage.value;

}


问题出在最后一行getImage方法...当我把隐藏字段'的值放在html图像的src属性中时,

页面卡在了一个infinte循环中。即使在服务器上完成图像生成,就好像页面永远不会完全加载
,所以

onload = getImage()不断被解雇再次。


添加返回功能没有帮助...也没有检查

top.PostBackDone。另外我试着把电话放在

window.onload ...


< head>

< script type = " text / javascript">

函数getMap()

{

if(arguments.callee.done)return;


arguments.callee.done = true;

var objHiddenImage =

document.getElementById(" mapImageSrc_hidden");

var objMapImage = document.getElementById(" mapImage");


objMapImage.src = objHiddenImage.value;

}

window.onload = getMap;

< / script>

< / head>


关于objMapImage .src = objHiddenImage.value,我得到null为null或

不是对象错误和图像没有显示...即使

调试清楚地显示objHiddenImage.value中的有效路径字符串!!!


任何建议非常感谢。


谢谢!

Hello,

Having an issue with JavaScript in my ASP.Net page.

I use some COTS, which for all intents and purposes, simply makes a
jpeg file and physically places it in a directory on the web server.

The page load codebehind, makes a connection to the jpeg creation
service and gets the path of the newly created image.

The sample code I''m providing is very simple... no rocket science here.
Here''s the code behind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Dim j As New jpegImage '' removed code for COTS & replaced
with psuedocode for posting purposes.
Dim c As New serviceConnector '' removed code for COTS & replaced
with psuedocode for posting purposes.
Dim urlImage

c = Server.CreateObject("Connector") '' removed code for COTS &
replaced with psuedocode for posting purposes.
c.ServerName = "DC1" '' Server''s name
c.ServerPort = 5300 '' Server''s port

j = Server.CreateObject("Jpeg") '' removed code for COTS &
replaced with psuedocode for posting purposes.
urlImage = j.GetImageAsUrl() '' string with path to newly
created jpeg file on server

Me.mapImageSrc_hidden.Value = urlImage

End Sub

Okay... you''ll see that I''m using a hidden field in the page markup.
There''s a bunch of reasons for this madness I''ll skip for now but I
need the client to load the image... not the server. Here''s what
happens next:

<asp:HiddenField ID="mapImageSrc_hidden" runat="server" />
<img id="mapImage" src="Images/null.gif" onload="getImage();" />

And in here''s the getImage method:

function getImage()
{
var objHiddenImage =
document.getElementById("mapImageSrc_hidden");
var objMapImage = document.getElementById("mapImage");

objMapImage.src = objHiddenImage.value;
}

The problem is on the last line of the getImage method... when I put
the hidden field''s value in the src property of the html image, the
page gets stuck in an infinte loop. It''s as if the page never fully
loads, even though image generation is complete on the server, so the
onload=getImage() keeps getting fired over and over again.

Adding a "return" to the function doesn''t help... nor does checking for
top.PostBackDone. Additionally I tried putting the call in
window.onload...

<head>
<script type="text/javascript">
function getMap()
{
if (arguments.callee.done) return;

arguments.callee.done = true;
var objHiddenImage =
document.getElementById("mapImageSrc_hidden");
var objMapImage = document.getElementById("mapImage");

objMapImage.src = objHiddenImage.value;
}
window.onload = getMap;
</script>
</head>

On objMapImage.src = objHiddenImage.value, I get the "null is null or
not an object" error and the image doesn''t show... even though
debugging clearly shows a valid path string in objHiddenImage.value!!!

Any suggestions are greatly appreciated.

Thanks!

推荐答案

Adam Sandler说:
Adam Sandler said:

>好的......你会看到我在页面标记中使用了隐藏字段。
有很多原因可供选择这个疯狂我现在会跳过,但我需要客户端加载图像...而不是服务器。
>Okay... you''ll see that I''m using a hidden field in the page markup.
There''s a bunch of reasons for this madness I''ll skip for now but I
need the client to load the image... not the server.



服务器永远不会加载图片。

他们总是由客户通过单独的请求加载

到服务器,所以抛弃所有废话,只需将图像的URL写入图像的src属性。

-

The server never loads images.
They''re always loaded by the client via a separate request back
to the server, so throw away all that nonsense and simply write
the URL of the image into the src attribute of the image.
--





1月24日下午1:02,Lee< REM0VElbspamt ... @ cox.netwrote:


On Jan 24, 1:02 pm, Lee <REM0VElbspamt...@cox.netwrote:

服务器永远不会加载图像。
The server never loads images.



你的绝对正确。而且我并不是故意暗示其他情况。


但是,服务器在运行时创建图像。客户端没有b $ b,也不会知道这个运行时创建。所以我将
使用ASP.NET中的隐藏字段作为服务器端之间的容器

和客户端。服务器端将运行时映像的url发送到隐藏字段的
,客户端跟踪DOM以从隐藏字段中提取值


Your absolutely correct. And I didn''t mean to imply otherwise.

However, the server creates the image at runtime. The client doesn''t
have, nor will it ever have, knowledge of this runtime creation. So I
use the hidden field in ASP.NET as a container between the server side
and client side. The server side sends the url of the runtime image to
the hidden field and the client side traces the DOM to pull the value
out of the hidden field.


只需将图像的URL写入图像的src属性即可。
simply write the URL of the image into the src attribute of the image.



好​​吧......但是创作一些document.write

staments或objMapImage.src = objHiddenImage.value之间的区别是什么? ????

okay... but what''s the difference between authoring some document.write
staments or objMapImage.src = objHiddenImage.value???


Adam Sandler说:
Adam Sandler said:

>

1月24日下午1:02,Lee< REM0VElbspamt ... @ cox.netwrote:
>
On Jan 24, 1:02 pm, Lee <REM0VElbspamt...@cox.netwrote:

>服务器从不加载图片。
>The server never loads images.


你的绝对正确。而且我并不是故意暗示其他情况。

然而,服务器在运行时创建图像。客户端没有,也不会拥有这个运行时创建的知识。所以我使用ASP.NET中的隐藏字段作为服务器端和客户端之间的容器。服务器端将运行时映像的url发送到隐藏字段,客户端跟踪DOM以将值拉出隐藏字段。


Your absolutely correct. And I didn''t mean to imply otherwise.

However, the server creates the image at runtime. The client doesn''t
have, nor will it ever have, knowledge of this runtime creation. So I
use the hidden field in ASP.NET as a container between the server side
and client side. The server side sends the url of the runtime image to
the hidden field and the client side traces the DOM to pull the value
out of the hidden field.


>只需将图像的URL写入图像的src属性即可。
>simply write the URL of the image into the src attribute of the image.


好吧......但是创作一些document.write
staments或objMapImage.src = objHiddenImage.value之间的区别是什么?


okay... but what''s the difference between authoring some document.write
staments or objMapImage.src = objHiddenImage.value???



除了一个可行的事实?

-

Besides the fact that one will work?
--


这篇关于从客户端代码加载图像时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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