如何从AJAX成功函数向asp文本框发送值....?

时间:2012-01-20 06:56:05

标签: asp.net ajax

$.ajax({
                    type: "POST",
                    url: "ClaretExamSchedule.aspx/LoadFatherInfo",
                    data: JSON.stringify({ appId: appId }),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                       **I want to pass the return values here to ASP Textboxes**
                    }
                });

鉴于上面的代码,我现在传递了一个用于代码隐藏方法LoadFatherInfo的参数 我返回了一个ArrayList,我想要使用文本框显示每个数据..对不起我的英语,但我希望你明白我的观点,任何帮助将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:0)

假设您的文本框和网络方法与下面的代码类似:

<input type="text" id="Father1" value="" class="father" />
<input type="text" id="Father2" value="" class="father" />
<input type="text" id="Father3" value="" class="father" />
   [WebMethod]
   public string[] LoadFatherInfo(appId appId)
   {
        // Do Stuff        
        var fatherInfo = new List();

        fatherInfo.Add("John");
        fatherInfo.Add("Jim");
        fatherInfo.Add("Joe");

        return fatherInfo.ToArray();
    }

您可以将ajax调用更改为类似于以下javascript的内容:

$.ajax({
    type: "POST",
    url: "ClaretExamSchedule.aspx/LoadFatherInfo",                     
    data: JSON.stringify({ appId: appId }),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: PopulateFatherBoxes,
    error: OnError
});


function PopulateFatherBoxes(data, status) {
    var i = 0;   
    $(".father").each(function() {
        $(this).val(data.d[i]);
        i++;
    });
}