我有一個ASP.Net網頁嘗試使用jquery .axax方法從asmx webservice檢索數據。當dataType =「text」時,ajax方法可以正確調用成功方法,但是當使用「json」的dataType時,我無法得到它。任何人都可以看到我缺少的東西嗎?我得到了 'JSON' 例如在網上http://weblogs.asp.net/jaredroberts/archive/2009/08/28/great-article-on-cascading-dropdown-list-and-jquery.aspx使用jQuery .ajax,當使用jQuery'json'vs'text'時不調用成功方法
客戶:
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"); }
});
}
Serverside集團Web服務調用:
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
您需要將json編碼爲「hello world」。 –