私は奇妙な問題を抱えています。それは常に現れるとは限りませんが、同じ要求で時々現れます。私のウェブサイト (localhost) には、自動読み込み機能を備えた ExtJS ストアがあり、ページの読み込み (F5 ボタンを押す) 後、サーバーのハンドラー ( * .ashx) から JSON を読み取ります。Handler は DB からデータを取得し、JSON にシリアライズします。F5キーを5回押すと4回動作します。5 回目の json-reader は、success=false および長さ 0 のデータを示します。
次のように、ハンドラーで時間遅延を使用する場合:
System.Threading.Thread.Sleep(1000);
50 倍の 49 倍の速度で動作します。しかし、Web サイトを高速化しようとすると、応答に遅延を設定するのは奇妙です。
問題について十分な情報がない場合は、助けていただくか、私に尋ねてください!
これが私のjsのサンプルです:
storePrefixes.on({
'beforeload': function () {
//...
},
'load': {
fn: function() {
if (storePrefixes.data.items.length > 0)
// ... working with response
else
// here is a problem
},
single: true
}
});
そしてサーバーコードがあります:
<%@ WebHandler Language="C#" Class="GetPrefixesInRD" %>
using System;
using System.Web;
using BCR.BLL;
public class GetPrefixesInRD : IHttpHandler, System.Web.SessionState.IReadOnlySessionState
{
private readonly PrefixNewBLL prefixeBLL = new PrefixNewBLL();
private readonly Newtonsoft.Json.JsonSerializer serializer = new Newtonsoft.Json.JsonSerializer();
public void ProcessRequest(HttpContext context)
{
var prefixes = prefixeBLL.GetPrefixesByExistPrefixInAccountingDocs(null, 1, false);
prefixes.Sort((x, y) => String.CompareOrdinal(x.Prefix, y.Prefix));
context.Response.ContentType = "application/json";
context.Response.Clear();
context.Response.BufferOutput = true;
serializer.Serialize(context.Response.Output, new { root = prefixes, total = prefixes.Count });
context.Response.Flush();
context.Response.End();
}
public bool IsReusable { get { return false; } }
}