1

状況では、JsonResult を返すコントローラーに対して、同じページで複数の ajax/json リクエストを作成しています。

これはセッション状態の問題であることはわかっています。コントローラー クラスに [SessionState(SessionStateBehavior.Disabled)] 属性を追加しましたが、何も機能していないようです。2 番目の ajax リクエストは戻りデータを取得しません。

コントローラー:

[SessionState(SessionStateBehavior.Disabled)]
public class IndexController : Controller
{}

2 つの json メソッド:

[AcceptVerbs(HttpVerbs.Get)]
    public JsonResult GetLatestListJSON()
    {
        Thread.Sleep(5000);
        ArticleRepository repo = new ArticleRepository();
        IList<ArticleModel> list = repo.GetLatestContent(10);

        return Json(list, JsonRequestBehavior.AllowGet);
    }

    [AcceptVerbs(HttpVerbs.Get)]
    public JsonResult GetCustomerJSON()
    {
        Thread.Sleep(5000);
       CustomerRepository Repo = new CustomerRepository();
        IList<Customer> cust= Repo.GetCustomer();

        return Json(cust, JsonRequestBehavior.AllowGet);
    }

2 番目のajax呼び出し、もう 1 つは非常に似ています。「成功」アラートは表示されません。

<script type="text/javascript">
        $(document).ready(function () {
            alert('before');            

            $.getJSON("/Index/GetCustomerJSON", null, function (data) {
                alert('succes');
                $("#loadingGifVideo").hide();
                $.each(data, function (index, mod) {                        

                });
            });
        });

みんなありがとう :)

4

1 に答える 1

0

GetCustomerJSON メソッドにブレークポイントを設定し、これを Visual Studio で実行すると、メソッドが呼び出されることはありますか? します

編集

エラーをキャプチャできるように、getJSON から ajax メソッドに切り替えてみてください。そのようです:

$.ajax({
  url: "/Index/GetCustomerJSON",
  dataType: 'json',
  data: null,
  success: function (data) { alert('success'); }
  error: function (data) { alert('error'); }
});

「エラー」アラートが表示されますか?

于 2012-05-01T20:47:06.787 に答える