See the following code.
Default.aspx:
---------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<title></title>
<script type="text/javascript">
function GetDateTime() {
var params = "{'msg':'From Client'}";
$.ajax
({
type: "POST",
url: "Default.aspx/GetServerDateTime",
data: params,
contentType: "application/json;charset=utf-8",
dataType: "json",
success: function (result) {
// myString = result.d;
alert(result.d);
},
error: function (err) {
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="GetMessage" type="button" value="Get Messages" onclick="GetDateTime();"/>
</div>
</form>
</body>
</html>
Default.aspx.cs
-----------------------------------------
using System;
using System.Web.Services;
public partial class _Default : System.Web.UI.Page
{
[WebMethod]
public static string GetServerDateTime(string msg)
{
String result="Result : " + DateTime.Now.ToString() + " - From Server";
return result;
}
}
Thanks & Regards
Hari Krishna
Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator