How to use Ajax in ASP. NET

  • 2021-08-03 09:59:05
  • OfStack

The format for applying Ajax in ASP. NET is as follows:

Foreground code (with JQuery library)


$.ajax({
    type: "POST",
    async: true,
    url: "../Ajax/ajax.ashx",
    dataType: "html",
    data: null
    success: function (result) 
    {
    //do successful sth
    },
    error: function (XMLHttpRequest, textStaus, errThrown) 
    {
    //do error sth
    }
})

The code in Ajax (1 generality handler) is as follows:


public void ProcessRequest (HttpContext context) 
{
context.Response.ContentType = "text/plain";
string result = "Hello World";
context.Response.Write(result);
}

The above is the site to introduce you ASP. NET Ajax usage of the relevant knowledge, I hope to help you, if you want to know more content, please pay attention to this site!


Related articles: