【发布时间】:2011-11-05 20:18:06
【问题描述】:
我创建了一个简单的 C# asp.net Web 服务函数,它返回一个字符串消息
我使用 jquery ajax 从页面调用它。
C#:
[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);
}
});
});
我的问题是为什么alert(msg); 不起作用
【问题讨论】:
标签: .net asp.net web-services