0

次の$.getメソッド呼び出しAjaxCallHandler.aspxページを非同期で使用しています。

        $.get("AjaxCallHandler.aspx?tc_id=" + tc_id, function (response) {
            //get All lblStatus
            var sel = "span[tc_id=" + tc_id + "]";
            //alert($(sel).text() + "  " + response);
            $(sel).text(response);
        });

AjaxCallHandler ページは、に基づいて成功/失敗tc_id is even or oddを返します。

public partial class AjaxCallHandler : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var str = Request.QueryString["tc_id"] != null ? Request.QueryString["tc_id"] as string : string.Empty;
        int tc_id;
        if (int.TryParse(str, out tc_id))
        {
            Response.Clear();            //clears the existing HTML
            Response.ContentType = "text/plain";  //change content type
            if (tc_id % 2 == 0)
                Response.Write("Pass");    //writes out the new name 
            else
                Response.Write("Fail");
            Response.End();             //end
        }
    }
}

カスタム属性を使用して、応答を Asp.Net ラベル (リピーター内に配置) にバインドするだけtc_idで、labelStatus は更新されません。

$(sel).text(response);Chrome コンソールで実行すると値が更新されることに注意してください 。

リピーターと の ViewState を無効にしようとしましたがlblStatus、どちらも役に立ちませんでした。

4

1 に答える 1

0

応答を処理するコードをashx ファイル (Generic Handler)に移動します。

ただし、応答を正しく取得していると言いますが、これを正確に呼び出すのはいつですか? ページがこのようにロードされた後?

 $(function () {
       $.get("AjaxCallHandler.aspx?tc_id=" + tc_id, function (response) {
                //get All lblStatus
                var sel = "span[tc_id=" + tc_id + "]";
                //alert($(sel).text() + "  " + response);
                $(sel).text(response);
            });
    });
于 2013-02-12T22:22:59.393 に答える