2012-01-20 36 views
1
$.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,我想使用文本框..對不起,我的英文顯示的每個數據,但我希望你明白我的意思,任何幫助都感激不盡。謝謝!如何從AJAX成功函數向asp文本框發送一個值....?

+0

對不起對於標籤asp-classic ..它總是發生在我身上。我總是隻標記ASP,但是當我發佈我的問題時,我總是看到asp-classic ...一個stackoverflow錯誤最有可能 – janrusselcalachan

+1

它不是一個錯誤。 ASP已經存在很長時間了。大多數人都明白朮語「ASP」是指基於COM和VBScript的老式「經典」形式。因此,stackoverflow有一個同義詞設置,以便標籤「asp」被識別爲「asp-classic」。你很可能使用ASP.NET,所以你應該使用標籤「asp.net」。 – AnthonyWJones

回答

0

假設你的文本框和Web方法將類似於下面的代碼的東西:

<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++; 
    }); 
} 
相關問題