简体   繁体   English

在ASP.net中从服务器端使用参数调用客户端JavaScript

[英]Calling client javascript with params from server side in ASP.net

I have an ASP.net webpage, that periodically (once in a minute) makes a call to my WCF REST service. 我有一个ASP.net网页,该网页会定期(每分钟一次)调用我的WCF REST服务。 My REST service responses some XML data. 我的REST服务响应一些XML数据。 After getting it I make some further operations on that on server side in my ASP page.Note, this post data process in ASP is required, I can't avoid it. 得到它后,我在ASP页的服务器端对此进行了进一步的操作。请注意,这是ASP中的后期数据处理所必需的,我无法避免。 I know my life would be easier without this step, but I must do it. 我知道没有这一步会使我的生活更轻松,但是我必须做到。

After I'd like to pass this data in XML format to a client side javascript, that can parse it and show infos to the user based on this data. 我想将XML格式的数据传递给客户端javascript后,可以对其进行解析并根据此数据向用户显示信息。 How can make this call from server side? 如何从服务器端发出此呼叫? What is the best pattern/practice to do it? 最佳的做法/做法是什么?

.net4/VS2010 .net4 / VS2010

if you want to call a function that already exists, that will load your data to the screen, you can tell the server to return your data and then ajax will grab that data and call a callback function. 如果要调用一个已经存在的函数,该函数会将数据加载到屏幕上,则可以告诉服务器返回您的数据,然后ajax将获取该数据并调用一个回调函数。 if you are not using ajax, you can reload the whole page with the new data. 如果您不使用ajax,则可以使用新数据重新加载整个页面。

HTTP is not designed to push data from the server to the client. HTTP并非旨在将数据从服务器推送到客户端。 I'm not really familiar with ASP but usually you have the following possibilities to "push" data to a client javascript application via HTTP: 我对ASP并不是很熟悉,但是通常您可以通过以下方式通过HTTP将数据“推送”到客户端javascript应用程序:

  • page reload via meta refresh (which doesn't actually push data;) ) 通过meta刷新重新加载页面(实际上并不推送数据;))
  • periodically polling an "job queue" URL using javascript 使用javascript定期轮询“作业队列” URL
  • comet (see http://en.wikipedia.org/wiki/Comet_(programming )) for an overview) 彗星(有关概述,请参见http://en.wikipedia.org/wiki/Comet_编程 ))
  • Web Sockets (which actually pushes data to the client but is only supported by newer browsers) Web套接字(实际上将数据推送到客户端,但仅受较新的浏览器支持)

I've been using atmosphere (http://atmosphere.java.net/) which works pretty well in java application containers, which provides an abstraction layer over the underlying technology. 我一直在使用大气(http://atmosphere.java.net/),它在Java应用程序容器中效果很好,该容器在基础技术上提供了一个抽象层。 I don't know if there is something similar out there in the ASP-world. 我不知道ASP世界中是否有类似的东西。

cheers Martin 给马丁加油

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

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