简体   繁体   English

jQuery从aspx页面检索数据

[英]JQuery Retrieving Data from aspx page

I want retrieve data from aspx page. 我想从aspx页面检索数据。 But, waiting data in static field if filling. 但是,如果要填充,请在静态字段中等待数据。

JQuery : jQuery的:

   $.ajax({
        url: "Services/JSON/GetMessage.aspx",
        type: "GET",
        dataType: "json",
        success: function (response) { alert(response.Text); },
        error: function (x, t, m) {
            if (t === "timeout") {
                alert("got timeout");
            } else {
                alert(t);
            }
        }
    })

Services/JSON/GetMessage.aspx 服务/JSON/GetMessage.aspx

<%@ Page Language="C#" %>
<% 
Response.Clear();
Response.ContentType = "text/json";
int tryCount = 0;
while (1 == 1)
{
    if (ClsStaticFields.Messages.Count > 0)
    {
        foreach(string message in ClsStaticFields.Messages) {
             Response.Write("{ Text:'" + message + "' }");
        }
    }
    tryCount ++;
    if (tryCount > 29) break; // 1 Minute wait and exit
    System.Threading.Thread.Sleep(2000); // 2 Second wait
}
Response.End();
%>

I was curious: 我很好奇:

  • is this waiting period affects other users? 这个等待期会影响其他用户吗?
  • is this cause locks on IIS or pages ? 这是导致IIS或页面锁定的原因吗?
  • is this usage effecting badly to CPU ? 这种用法对CPU有严重影响吗?

I see that you use GetMessage.aspx page, an aspx page that is probably connected with session and this affect other users. 我看到您使用的是GetMessage.aspx页面,这是一个可能与会话连接的aspx页面,这会影响其他用户。

Disable the session for that page if this is possible and all is ok. 如果可能的话,请禁用该页面的会话,并且一切正常。

<%@ Page Language="C#" EnableSessionState="false" %>

relative: 相对的:

Web app blocked while processing another web app on sharing same session 在共享同一会话时处理另一个Web应用程序时,Web应用程序被阻止
What perfmon counters are useful for identifying ASP.NET bottlenecks? 哪些性能计数器可用于识别ASP.NET瓶颈?
Replacing ASP.Net's session entirely 完全取代ASP.Net的会话

The full view 全图

I do not think that is good idea the way you have make your waiting for the message inside this close loop and I suggest two alternatives. 我认为在这种闭环内等待消息的方式并不是一个好主意,我建议两种选择。

Make the periodical call on browser using a javascript timer . using a javascript timer在浏览器上using a javascript timer定期调用。 Ether way you get the messages every 2 seconds, so why not call for that message from browser every couple of seconds ? 以其他方式,您每隔2秒就会收到一条消息,那么为什么不每隔两秒钟从浏览器中调用该消息呢?

Or even better to use the comet method to call the server. 甚至最好使用Comet方法来调用服务器。 Here is an example of comet in asp.net : http://www.aaronlerch.com/blog/2007/07/08/creating-comet-applications-with-aspnet/ 这是asp.net中的彗星示例: http : //www.aaronlerch.com/blog/2007/07/08/creating-comet-applications-with-aspnet/

Why is not good, first you use thread that belong to asp.net iis, and is connected with the browser call, that is leave an open connection and very soon your open connections will be run out, maybe also the asp.net net threads have problem with that. 为什么不好,首先使用属于asp.net iis的线程,并与浏览器调用连接,即保持开放连接,很快您的开放连接将用完,也许还有asp.net网络线程有问题。

Periodically check like yours is better to be done using Timers and not close loops with thread waits, and here the best place for that is the browser him self. 最好像使用定期定时器那样检查,最好使用Timers而不是使用线程等待的闭环进行,这里最好的地方是他自己的浏览器。

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

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