グラフをプロットするために C# から入力を取得するチャートを使用しています。C# から jQuery に値を返すために JSON を使用しています。とにかくそれは私を助けません、私は何を間違えましたか?
これは私のaspxコードです:
<script type="text/javascript">
$(document).ready(function () {
var source = {};
$.ajax({
type: 'POST',
dataType: 'json',
url: "Default.aspx/getall",
contentType: 'application/json; charset=utf-8',
cache: false,
success: function (response) {
source = $.parseJSON(response.d);
},
error: function (err) {
alert('Error');
}
});
</script>
そして、これは私のC#コードです:
public class sampledata
{
public string Day { get; set; }
public int Keith { get; set; }
public int Erica { get; set; }
public int George { get; set; }
}
public partial class _Default : System.Web.UI.Page
{
List<sampledata> s = new List<sampledata>();
protected void Page_Load(object sender, EventArgs e)
{
s.Add(new sampledata { Day = "monday", Keith = 20, Erica = 15, George = 25 });
s.Add(new sampledata { Day = "tuesday", Keith = 25, Erica = 20, George = 35 });
Session["data"] = s;
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static List<sampledata> getall()
{
List<sampledata> data = (List<sampledata>)HttpContext.Current.Session["data"];
return data;
}
}