Try like this
Html:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="jquery-1.8.2.min.js"></script>
<script type="text/javascript">
function SendDataToServerUsingAjax() {
var poststring = "pass your text to the server";
var parameters = JSON.stringify({ 'parameterName': poststring });
$.ajax({
type: "POST",
url: "WebForm1.aspx/ServerMethodName",
data: parameters,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert(response.d);
},
failure: function (response) {
alert(response.d);
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button Text="send data to server" OnClientClick="SendDataToServerUsingAjax(); return false" runat="server" />
</div>
</form>
</body>
</html>
Code Behind:
[System.Web.Services.WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string ServerMethodName(string parameterName)
{
return "success";
}