根据响应流更新图像
是否可以使用 ASP.NET 通用处理程序的响应流更新 HTML 页面上的图像?
例如,如果我在处理程序上有以下代码:
// http://www.example.com/?Guid=<AccountGuid>
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "image/png";
context.Response.WriteFile("~/images/test.png");
}
如何使用 .ajax 在 jQuery 中调用处理程序,并在页面上设置与处理程序返回的图像相同的图像? 我现在忽略了查询字符串变量,因为我只想让它工作。
其次,如果我可以做到上述,我如何循环遍历页面上属于“类”的所有 DIV content”,从隐藏字段中选择一个 guid 用作我的查询字符串参数,并更新同一内容 DIV 标记内的关联图像?
内容 div 标签如下所示:
<div class="content">
<asp:TextBox runat="server" Id="HiddenField_1" Value="C142E68F-B118-4565-9A9E-B2347F0B6D5B"/>
<img src="#"/>
</div>
<div class="content">
<asp:TextBox runat="server" Id="HiddenField_2" Value="GJ38AD23-B118-4565-9A9E-B2347F0B6D5B"/>
<img src="#"/>
</div>
我希望定期更新所有图像,因此本质上,作为快速回顾,我需要:
- 循环遍历我的所有“内容”类 DIV,每 n 发生一次。秒。
- 从隐藏字段中提取 GUID。
- 调用我的 ASSX 处理程序以获取更新的图像。
- 将返回的图片设置为页面对应的图片。
这是一件很难实现的事情吗?如果没有,我需要做什么才能以上述方式实现此功能?
Is is possible to update an image on an HTML page using the response stream of an ASP.NET Generic Handler?
For example, if I have the following code on a handler:
// http://www.example.com/?Guid=<AccountGuid>
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "image/png";
context.Response.WriteFile("~/images/test.png");
}
How can I call the handler in jQuery, using .ajax, and set an image on the page equal to the image that is returned by the Handler? I am ignoring the query string variable at the moment as I just want to get this working.
Secondly, if I can do above, how can I loop through all of DIVs on the page that are of class "content", select a guid out of a hidden field to use as my query string parameter, and update the associated image within the same content DIV tag?
A content div tag would look as follows:
<div class="content">
<asp:TextBox runat="server" Id="HiddenField_1" Value="C142E68F-B118-4565-9A9E-B2347F0B6D5B"/>
<img src="#"/>
</div>
<div class="content">
<asp:TextBox runat="server" Id="HiddenField_2" Value="GJ38AD23-B118-4565-9A9E-B2347F0B6D5B"/>
<img src="#"/>
</div>
I would like to have all the images updated on a periodic interval, so essentially, as a quick recap, I would need to have:
- A loop through all of my DIVs of class "content", occuring every n. seconds.
- Extractation the GUID from the hidden field.
- A call to my ASHX handler to get the updated image.
- Set the returned image to the corrisponding image on the page.
Is this something that would be difficult to achieve? If not, what would I need to do to make this function in the above manner?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 jquery 通过适当的 url 参数更改图像的 src 值。它将调用 ashx 处理程序并渲染新图像。
Use jquery to change the src value of the images with the appropriate url parameters. It'll call the ashx handler and render the new image.