How can I get JSONdata from ASP.NET and send it to jQuery? (implementation of FullCalendar)

I am trying to get JSON data into a jQuery variable using ASP.NET (not MVC):

$(document).ready(function () { $('#calendar').fullCalendar({ events: GetEvents(start, end) //This line is invalid } } 

In MVC, it could just be events: "/Calendar/GetEvents/" , which will call the CalendarController GetEvents () method.

But since I am not using MVC, I started following this guide to try to call server methods from the client.

In the second stage, he tells me that for this you need to create a static method:

 [System.Web.Services.WebMethod] public static string Message() { return "Hello from the server-side World!"; } 

But I need to have access to non-static variables like Session[] inside the method, so I can’t understand how this approach will work.

Is there a better approach to getting JSON data extracted from an aspx.cs method that does not require a direct server-side call? Or is there a way to use a session that I don't know about?

+2
source share
1 answer

Instead of calling the session directly, use HttpContext.Current.Session or make it a static property on your page:

 private static HttpSessionState MySession { get { return HttpContext.Current.Session; } set { return HttpContext.Current.Session = value; } } 
+1
source

All Articles