本文介绍了如何将数据从C#发送到JavaScript/AJAX网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我需要c#服务器能够将数据发送回HTML5网页,而HTML5先前已将数据发送到服务器.服务器正在从另一个应用程序检索数据,然后需要将该数据发送到要显示的网页.

Basically, I have a need for a c# server to be able to send data back to an HTML5 webpage which has previously send data to the server. The server is retrieving data from another application and this data then needs to be send to the webpage to be displayed.

此c#服务器在.NET CF 3.5上运行,因此不能使用websocket(不支持).

This c# server is running on .NET CF 3.5 so websockets are not an option (not supported).

我在其他地方看到了一些建议,但没有什么适合这种特殊情况的必要标准.大多数其他实现似乎是在网页仅 等待该数据被发送的基础上工作的.

I have seen some suggestions elsewhere but nothing which fits the necessary criteria for this particular situation. Most other implementations seem to work on the basis that the webpage will only be waiting for this data to be sent over.

欢迎任何建议!

推荐答案

如果没有websockets选项,那么您将剩下彗星.

If websockets are not an option then you are left with Comet.

在客户端,您可以执行以下操作:

Client-side you could do something like this :

(function poll(){
    $.ajax({
        url: "url",
        success: function(data) { /*display data*/ },
        complete: poll,
        timeout: 30000 });
})();

这意味着将每30秒发送一次ajax请求.

Which means an ajax request will be sent every 30 seconds.

这不如websockets高效,但效果很好.

This is not as performant as websockets but it works quite well.

这篇关于如何将数据从C#发送到JavaScript/AJAX网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 05:20