Hi @Ashok Kumar,
What you need to get is the <form> tag instead of the one with id form.But this method can only get the form of the current page.
var queryString = $('form').serializeArray();
POST data is data that is handled server side. And Javascript is on client side. So there is no way you can read a post data using JavaScript.
You can use Request.Form Collection. The Form collection retrieves the values of form elements posted to the HTTP request body, with a form using the POST method.
page-2:
<script type="text/javascript">
$(document).ready(function () {
$.ajax({
url: "page-2.aspx/getMessage",
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
alert(msg.d);
}
});
});
</script>
public static string message { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
if (Request.RequestType == "POST")
{
message = Request.Form["data"];
}
}
}
[WebMethod]
public static string getMessage()
{
return message;
}
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.