ASP.NET AJAX without Update Panel

What is the best data support practice for asp.net 2.0-3.5 ajax web application? I do not want to use update panels, just text data (JSON). Should I use web services? Or is there another way.

+3
source share
2 answers

Errrr ... Use the .aspx page? What are handlers for?

You just need to create a generic base handler that takes care of serializing json (de) (e.g. using Json.net ) and then execute handlers for your ajax calls.

public abstract class JsonHandlerBase<TInput, TOutput> : IHttpHandler
{
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "application/json";
        TInput input = (TInput)context.Request; // Desesialize input
        TOutput output = ProcessRequest(context, parameter);

        string json = (string)output; // Serialize output
        context.Response.Write(json);
    }

    public abstract TOutput ProcessRequest(HttpContext context, TInput input);

    public bool IsReusable { get { return false; } }
}

This is just an example, you decide if you need in your base handler.

+7
source

aspx- JSON. , Html aspx, Response.Write() .

JS JQuery Ajax.

Asp.Net MVC. MVC JsonResult JQuery, Ajax.

+1

Source: https://habr.com/ru/post/1704391/


All Articles