Quantcast
Channel: ASP.NET AJAX + Ajax Control Toolkit (ACT)
Viewing all articles
Browse latest Browse all 5678

Cannot get result from AJAX

$
0
0

 

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?


 

 

 

 

 

 


Viewing all articles
Browse latest Browse all 5678

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>