I created a simple C # asp.net web service function that returns a string message
and I call it from the page using jquery ajax.
FROM#:
[WebMethod] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public string HelloWorld() { return DateTime.Now.ToString(); }
JS:
$(document).ready(function() { //alert("ready"); $.ajax({ type: "POST", contentType: "application/json; chatset=utf-8", url: "WebService2.asmx/HelloWorld", data: "{}", dataType: "json", success: function(msg) { //alert(msg); //doesnt works alert(msg.d); } }); });
My question is: why alert(msg); does not work
source share