简体   繁体   English

在 Javascript 中读取服务器端变量

[英]Reading Server-Side Variable in Javascript

I am using embeded flash for displaying the camera video inside an asp.net project for passing the camera inf.我正在使用嵌入式闪光灯在 asp.net 项目中显示相机视频以传递相机信息。 I am writing variables from flash to the server using Tamper Data extension I know it is sending ok.我正在使用篡改数据扩展将变量从闪存写入服务器我知道它发送正常。

The problem is reading it with javascript.问题是用javascript阅读它。 How can I?我怎样才能? I'm trying to use JSP with the <%...%> but I am not able to read it properly.我正在尝试将 JSP 与<%...%>但我无法正确读取它。

This is the code I am using:这是我正在使用的代码:

document.getElementById("txtID").value = "<%=varActionServer.Value%>";

Where txtID is a textbox and varActionServer.Value is the value of the Server variable that I want.其中txtID是一个文本框, varActionServer.Value是我想要的 Server 变量的值。

You need to understand the big gap between client-side and server-side.您需要了解客户端和服务器端之间的巨大差距。 Serverside variables can only tell you what the server knew when it built the page and before it sent it to the client.服务器端变量只能告诉您服务器在构建页面时以及将其发送到客户端之前知道的内容。 JSP is a serverside technology and it, too, can only know what the server knew before it sent the page. JSP 是一种服务器端技术,它也只能知道服务器在发送页面之前知道什么。

What you are trying to achieve is client-side;您要实现的是客户端; that after the page has gone to the client, the page can still be updated.页面到达客户端后,页面仍然可以更新。 For this, you must forget JSP.为此,您必须忘记 JSP。

I assume that you are going via the server because you already have a working solution that gets data from the camera, through flash, to the server.我假设您正在通过服务器访问,因为您已经有了一个工作解决方案,可以通过闪光灯将数据从相机获取到服务器。 In that case you can read data from the server using ajax.在这种情况下,您可以使用 ajax 从服务器读取数据。 The simplest route is jQuery.ajax最简单的路由是jQuery.ajax

Another option might be to throw out the flash solution and use something else.另一种选择可能是丢弃闪存解决方案并使用其他解决方案。 Here' an SO question about that approach: Access camera from a browser这是一个关于这种方法的问题: 从浏览器访问相机

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM