我试图从webmethod获取bool,但得到了xml字符串。不想在客户端解析XML。 在.net MVC中,我已经通过returnin'JSON实现了它,如何通过WebForms制作技巧?AJAX从asp.net获取布尔值webmethod
将WebMethod:
[System.Web.Services.WebMethod]
public bool MyService(string _container)
{
return true;
}
的AJAX调用:
$.ajax({
type: "POST",
url: '/WebMethods.asmx/MyService',
contenttype: "application/json; charset=utf-8",
data: { _container: JSON.stringify(params) },
datatype: 'json',
success: function (data) {
if(data) {
MakeStuff();
}
}
});
我已经有了: <boolean xmlns="%myWebmethodUrl%">true</boolean>
杜佩http://stackoverflow.com/questions/18244696/how-to-ret urn-json-with-asp-net-jquery? – Vladimirs 2014-11-21 10:14:29
@Vladimirs不幸的是,没有。 [解决方案](http://stackoverflow.com/questions/18244696/how-to-return-json-with-asp-net-jquery)只是改变了从布尔型到字符串的XML类型。不是出路。 – Dunadan 2014-11-21 10:30:29