1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//aspx.cs
using System.Web.Script.Serialization;
namespace Test_Kmh.Dev_ASP.NET
{
  public partial class test01 : System.Web.UI.Page
  {
    private string type 
    { 
        get 
        { 
            return string.IsNullOrEmpty(Request.Form["Type"]) ? string.Empty : Request.Form["Type"]; 
        } 
    }
    // 리턴클래스 설정
    ReturnClass rtnClass = new ReturnClass();
    protected void Page_Load(Object sender, EventArgs e)
    {
      if(Type == "1")
      {
        rtnClass.RtnStr = "ABC";
        return;
      }
    }
    /// 
    /// Json형식으로 리턴
    /// 
    protected override void OnPreRender ( EventArgs e )
    {
      base .OnPreRender ( e);
      string json = new JavaScriptSerializer () .Serialize ( retInfo);
      Response .Write ( json);
    }
    /// 
    /// 리턴 클래스
    /// 
    public class ReturnClass
    {
      public string RtnStr = "";
    }
  }
}
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//javascript
<script type"text/javascript" src="jq-1.10.2.js"></script>
<script type"text/javascript">
  function ajaxCall(){
    $.ajax({
      type: 'POST',
      cache: false,
      async: false,
      url: 'test01.aspx',
      dataType: 'html',
      data : { type: '1' },
      success: function(result){
        var data = jQuery.parseJSON(result);
        //리턴받아서 출력
        alert(data.RtnStr);
      }
    });
  }
</script>
cs


+ Recent posts