gpt4 book ai didi

jquery - 如何通过mvc进行通知和在线直播

转载 作者:行者123 更新时间:2023-12-01 01:35:24 25 4
gpt4 key购买 nike

如何通过mvc进行通知和在线直播?我通过 jquery 使用 $.ajax() 。示例:

window.setInterval(function () {
$.ajax({
url: "",
type: "GET",
data: {},
success: function (data) {

}
})
},1000);

你是否通过$.$向服务器发送请求的过程? Ajax频繁通过Timer对服务器或数据库有影响吗?

最佳答案

我认为使用 SignalR 更好.

ASP.NET SignalR is a new library for ASP.NET developers that makes it incredibly simple to add real-time web functionality to your applications. What is "real-time web" functionality? It's the ability to have your server-side code push content to the connected clients as it happens, in real-time.

You may have heard of WebSockets, a new HTML5 API that enables bi-directional communication between the browser and server. SignalR will use WebSockets under the covers when it's available, and gracefully fallback to other techniques and technologies when it isn't, while your application code stays the same.

SignalR also provides a very simple, high-level API for doing server to client RPC (call JavaScript functions in your clients' browsers from server-side .NET code) in your ASP.NET application, as well as adding useful hooks for connection management, e.g. connect/disconnect events, grouping connections, authorization.

关于jquery - 如何通过mvc进行通知和在线直播,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15158842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com