I have a file called "index.aspx" and part of the code is as follows:
var ServerTime = {
get: function(){
var ServerTime = "nothing here";
$.ajax({
type: "POST",
url: "Index.aspx.cs/getServerTime",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
ServerTime = msg.d;
}
});
return ServerTime;
}
}
The above code will call the method "getServerTime" in my "Index.aspx.cs" file.
[System.Web.Services.WebMethod]
public static string getServerTime(string DateTimeFormat)
{
if (DateTimeFormat == null)
{
DateTimeFormat = "HHmm";
}
String message = "nothing";
try
{
message = DateTime.Now.ToString(DateTimeFormat);
}
catch (Exception err)
{
message = "Exception found: " + err;
}
return message;
}The strange things is that when I called the following code:
onsole.log(" Time Server: " + ServerTime.get());I get the following result, which is not what I expected
Time Server: nothing here
Is there something wrong with my code?