Javascript jQuery Ajax WCF后返回布尔值
我似乎找不到关于如何从jQuery发布到WCF web服务并捕获返回的布尔值的示例。这是我到目前为止返回JSON数据的代码: JavascriptJavascript jQuery Ajax WCF后返回布尔值,javascript,jquery,wcf,Javascript,Jquery,Wcf,我似乎找不到关于如何从jQuery发布到WCF web服务并捕获返回的布尔值的示例。这是我到目前为止返回JSON数据的代码: Javascript function VerifyPINData(pin) { $.ajax({ type: 'POST', url: "http://localhost:8523/WebService/VerifyPINData?pinData=" + pin, data: JSON.stringify, contentType: 'a
function VerifyPINData(pin) {
$.ajax({
type: 'POST',
url: "http://localhost:8523/WebService/VerifyPINData?pinData=" + pin,
data: JSON.stringify,
contentType: 'application/json; charset=utf-8',
success: function(data){ alert("result is: " + data); },
error: function() {alert("error"); },
complete: function() { alert("complete"); }
});
}
WCF
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "VerifyPINData?pinData={pinData}")]
bool VerifyPINData(string pinData);
任何帮助都将不胜感激。解决了:
将返回的数据转换为布尔值:
success: function(data){ alert("result is: " + Boolean(data)); },
在WCF中将响应指定为JSON
[OperationContract]
[WebInvoke(Method = "POST", UriTemplate = "VerifyPINData?pinData={pinData}", ResponseFormat = WebMessageFormat.Json)]
bool VerifyPINData(string pinData);