Script in ASPX page:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function ()
{
$("#Button2").click(function ()
{
var num = $('#TextBox1').val();
$.ajax({
type: "POST",
url: "Default.aspx/GetSquareOfNumber", // Your page and function name
data: '{param: "' + num + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data)
{
if (data.d != null)
{
alert(data.d);
}
},
failure: function (response)
{
console.log(response.d);
}
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<input id="Button2" type="button" value="button" />
</div>
</form>
</body>
</html>
Namespace:
using System.Web.Services;
Code behind C#:
[WebMethod]
public static int GetSquareOfNumber(int param)
{
return param * param;
}
No comments:
Post a Comment