Gives solution for any Error occurs in any Programming Language, .Net Core 3.1, 3.0, C#,Asp.Net,Sqlserver,MVC,Java,Php,Html,Css,Jquery,errors and solutions,Latest News,Technology

Wednesday, 10 August 2016

How to call jQuery AJAX function in ASP.NET, C# Master page using WebMethod

No comments :
Here is the explanation of  how to call AJAX function in a Master Page in Asp.Net, C#.

In below function, place "/" symbol followed by any page name in the project followed by method name in url.
Example: URL: "/Pagename.aspx/WebMethodName"

$.ajax({
                    type: "POST",
                    url: "/Default.aspx/GetRecentTickets",   //Here place "/" before page name
                    data: '{}',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                      alert(response.d);
                    }
             });
CS Page:

[WebMethod]
        public static string GetRecentTickets()
        {
           //Code to get data
        }

Note: If not a Master Page, write a particular page name where you want to call the AJAX Method followed by Method name.

Example : URL: "Login.aspx/GetDetails"

$.ajax({
                    type: "POST",
                    url: "Login.aspx/GetDetails",   //Here no need to add "/" before page name
                    data: '{}',
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (response) {
                      alert(response.d);
                    }
             });

No comments :

Post a Comment