我创建了一个简单的C#asp.net Web服务函数,它返回一个字符串消息
,我使用jquery ajax从页面调用它.
C#:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string HelloWorld() {
return DateTime.Now.ToString();
}
Run Code Online (Sandbox Code Playgroud)
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);
}
});
});
Run Code Online (Sandbox Code Playgroud)
我的问题是,为什么 alert(msg);犯规作品