Created
December 3, 2016 06:21
-
-
Save smetronic/6a47ebd3275ff66ec654dd0ba9277d9f to your computer and use it in GitHub Desktop.
Calling ASP.Net Page Method using jQuery AJAX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Ajax.Default" %> | |
<!DOCTYPE html> | |
<html> | |
<head runat="server"> | |
<title></title> | |
</head> | |
<body> | |
<form id="form1" runat="server"> | |
</form> | |
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script> | |
<script> | |
$.ajax({ | |
type: "POST", | |
url: "Default.aspx/GetResult", | |
data: '{variable: 123456 }', | |
contentType: "application/json; charset=utf-8", | |
dataType: "json", | |
success: function (response) { | |
alert(response.d); | |
}, | |
failure: function(response) { | |
alert(response.d); | |
} | |
}); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Web.Services; | |
namespace Ajax | |
{ | |
public partial class Default : System.Web.UI.Page | |
{ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
} | |
[WebMethod] | |
public static string GetResult(int variable) | |
{ | |
return "Data " + variable; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment