Hello everyone,
I am using jQuery Ajax post value from client side but its not working.
I am unable to figure kindly please help me.
Any suggestions will be appretiated.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="AJAX.Test" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-3.4.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#btn').click(function () {
var no = 123;
$.ajax({
url: 'Test.aspx/show',
method: 'post',
contentType: 'ápplication/json',
data: '{Id:' + no + '}',
dataType: 'json',
success: function (data) {
alert(data.d.id);
},
failure: function (data) {
alert(data.d);
}
});
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<input type="button" id="btn" value="Submit" />
</form>
</body>
</html>
namespace AJAX
{
public partial class Test : System.Web.UI.Page
{
[WebMethod]
public static string show(string id)
{
return id;
}
}
}