I'm facing an issue with my webstatic method that converts my dataset into JSON. I want to retrieve this JSON in my JavaScript file, but unfortunately nothing is appearing in my div. As a newcomer to ASP.NET and JSON, I must be doing something wrong here. My main goal is simply to transfer the JSON from the code behind file to JavaScript.
<asp:ScriptManager ID="ScriptManager1" EnablePageMethods="true" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div id="Result">Click here for the time.</div>
<script type="text/javascript">
$(document).ready(function () {
$("#Result").click(function () {
$.ajax({
type: "POST",
url: "A2_JVV.aspx/ds2json",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$("#Result").text(msg.d);
}
});
});
});
</script>
In my A2_JVV.aspx.cs page, I have utilized Newton JSON to convert my dataset into JSON.
[WebMethod]
public static string ds2json()
{
DataSet ds = new DataSet();
ds=(DataSet)HttpContext.Current.Session["dsgrr"];
return JsonConvert.SerializeObject(ds.Tables["jv"], Formatting.Indented);
}
Error in Chrome Console:
POST http://localhost:49388/WebSite2/A2_JVV.aspx/ds2json 500 (Internal Server Error)
c.extend.ajax @ jquery-1.4.2.min.js:130(anonymous function)
@ A2_JVV.aspx:207c.event.handle
@ jquery-1.4.2.min.js:55c.event.add.j.handle.o
@ jquery-1.4.2.min.js:49