简体   繁体   English

ICallbackEventHandler请求每1秒发出一次

[英]ICallbackEventHandler request every 1 second

I have code that fires an ICallbackEventHandler every 1000ms. 我有代码,每1000毫秒触发一次ICallbackEventHandler。 When I run this code locally the data responds quick like every 1 second. 当我在本地运行此代码时,数据会像每1秒一样快速响应。

I then uploaded this on the server and sometimes the data responds 1 second and sometimes 3 seconds and then sometimes 6-7 seconds, why is this? 然后,我将其上传到服务器上,有时数据响应1秒,有时3秒,有时6-7秒,这是为什么?

The bit of code that makes this recursive call every 1 second to the server is below: 下面是每1秒对服务器进行一次此递归调用的代码位:

function MessageServerResponse(param, context) {
    if (param.length > 0) {
        var splitParam = param.split("~");
        var id = splitParam[0];
        var data= splitParam[1];

        $('#' + id).prepend(data);
    }

    setTimeout("MessageServerRequest();", 1000);
}

if ur the only person who use server, the response would be always 1 second. 如果您是唯一使用服务器的人,则响应将始终为1秒。 and u cannot expect client to dedicately response your script 而且您不能指望客户端专门响应您的脚本

1 of my trick to make it faster 我的技巧之一,使其更快

  • if u use normal <form> postback put as less as u can in form. 如果您使用普通的<form>回发,请尽量减少您在表单中的回送。 more html in form means more data transfer 更多的html形式意味着更多的数据传输
  • if u use updatepanel just keep it small or make dedicate update panel to boost performance 如果您使用updatepanel,请使其保持较小尺寸或使用专用的更新面板来提高性能
  • for jquery, i'd suggest $.ajax({cache:true}) 对于jQuery,我建议$ .ajax({cache:true})

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

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