【发布时间】:2011-09-20 20:46:04
【问题描述】:
我有一个 ASP.Net 网页尝试使用 jquery .axax 方法从 asmx 网络服务中检索数据。当dataType =“text”时,ajax方法正确调用了成功方法,但是当使用“json”的dataType时我无法让它返回。谁能看到我错过了什么?我在http://weblogs.asp.net/jaredroberts/archive/2009/08/28/great-article-on-cascading-dropdown-list-and-jquery.aspx 在线获取“json”示例
客户:
function getText() {
alert("getText");
$.ajax({
type: "POST",
url: "test.asmx/HelloWorld",
dataType: "text",
success: function(response) { alert("text"); }
});
}
function getJson() {
alert("getJson");
$.ajax({ type: "POST",
url: "test.asmx/HelloWorld",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) { alert("json"); }
});
}
服务器端 Web 服务调用:
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
【问题讨论】:
-
您需要对“hello world”进行 json 编码。