Wednesday, 10 August 2016
How to call jQuery AJAX function in ASP.NET, C# Master page using WebMethod
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);
}
});
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);
}
});
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment