我可以使用jQuery調用我的webservice如果contentType =「application/x-www-form-urlencoded; charset = utf-8 「ASMX webservice不返回JSON,只能使用應用程序POST/x-www-form-urlencoded contentType
這將然而,返回XML:<string>[myjson]</string>
如果嘗試使用張貼到服務‘應用程序/ JSON;字符集= UTF-8’我接收500錯誤與空棧跟蹤和ExceptionType 。我的web服務功能從來沒有被打過,所以我不太清楚如何調試這種情況。
我的方法和類裝飾有適當的屬性,並設置爲使用JSON作爲它們的響應類型(我的wsdl和disco文件也是如此)。我已經安裝了Ajax擴展和web.config中的必需條目。
這是在SharePoint服務器場上,但我不確定這會帶來太多的不同。我在所有WFE上部署了web.config更改,並安裝了ajax擴展。該服務再次運行,它只是不接受任何內容,而是默認的內容類型。
不知道我很想念這裏,夥計們......
我的Ajax調用:
$.ajax({
type: "POST",
url: "/_vti_bin/calendar.asmx/Test",
dataType: "json",
data: "{}",
contentType: "application/json; charset=UTF-8",
success: function(msg){
alert(msg);
},
error: function(xhr, msg){ alert(msg + '\n' + xhr.responseText); }
});
我的web服務類:
[WebService(Namespace = "http://namespace")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService()]
public class CalendarService : WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string Test()
{
return "Hello World";
}
}
執行AJAX請求時,ASP.NET MVC 1.0上發生的情況也是如此。 – 2010-09-24 15:25:44