カウンターを1アップして返すAjaxを実装してみましたが、返り値がundefiedになってしまいます。
どなたか、わかる方はご教示ください。
C#
1<%@ Page Language="C#" %> 2<%@ Import Namespace="System.Collections.Generic" %> 3<%@ Import Namespace="System.Linq" %> 4<%@ Import Namespace="System.Web.Services" %> 5<%@ Import Namespace="System.IO" %> 6<script runat="server"> 7 protected void Page_Load(object sender, EventArgs e) 8 { 9 if (!IsPostBack) 10 { 11 12 } 13 else 14 { 15 16 } 17 } 18 19 [WebMethod] 20 public static string countUp_click(int id, int count) 21 { 22 dynamic dataSet = new { id = id.ToString(), count = count++.ToString() }; 23 var s = new System.Web.Script.Serialization.JavaScriptSerializer(); 24 return s.Serialize(dataSet); 25 } 26 27</script> 28 29<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 30 31<html xmlns="http://www.w3.org/1999/xhtml"> 32<head runat="server"> 33 <head> 34 <title>Single-File Page Model</title> 35 <script src="Scripts/jquery-1.4.1.js"></script> 36 </head> 37 38</head> 39<body> 40 <form id="form1" runat="server"> 41 <div id="id1"> 42 <input type="submit" id="countUp" value="カウントアップ" /> 43 </div> 44 <div id="count"> 45 46 </div> 47 </form> 48 <script type="text/javascript"> 49 $(document).ready(function () { 50 $("#countUp").click(function () { 51 var hostUrl = "WebForm1.aspx/countUp_click"; 52 var param1 = 1; 53 var param2 = 10; 54 $.ajax({ 55 url: hostUrl, 56 type: "POST", 57 dataType: "application/json; charset=UTF-8", 58 data: JSON.stringify('{ "id" : ' + param1 + ', "count" : ' + param2 + ' }'), 59 success: function (data) { 60 alert("ok"); 61 // undefied と表示される 62 window.alert(data.id); 63 // undefied と表示される 64 window.alert(data.count); 65 $('#count').html(data.count); 66 }, 67 error: function (XMLHttpRequest, textStatus, errorThrown) { 68 alert("error"); 69 window.alert(XMLHttpRequest.toString()); 70 window.alert(textStatus.toString()); 71 window.alert(errorThrown.toString()); 72 } 73 }); 74 75 }); 76 }); 77 </script> 78</body> 79</html> 80
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2015/08/18 09:25
2015/08/18 09:34
2015/08/18 14:11
2015/08/19 01:37
2015/08/20 02:40
2015/08/20 12:12
2015/08/21 00:48
2015/08/24 06:05