2012-12-05 54 views
2

我似乎無法找到如何從jQuery發佈到WCF Web服務並捕獲返回的布爾值的示例。這是我的代碼到目前爲止返回JSON數據:jQuery Ajax WCF POST - 返回布爾值

的Javascript

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); 

任何幫助,將不勝感激。

回答

0

想通了:

success: function(data){ alert("result is: " + Boolean(data)); }, 

指定在WCF

[OperationContract] 
    [WebInvoke(Method = "POST", UriTemplate = "VerifyPINData?pinData={pinData}", ResponseFormat = WebMessageFormat.Json)] 
    bool VerifyPINData(string pinData); 
將響應作爲JSON:爲布爾

鑄造返回的數據