2015-02-23 208 views
0

我想使用WCF Web服務。該服務正在瀏覽器中以Json格式返回結果,但是當我試圖通過ajax調用來獲取數據時,它給出了錯誤。我的代碼如下。該服務在公共服務器上運行,並在angularjs中使用。在angularjs中,服務正在返回Json數據。這是我第一次使用WCF svc服務調用。ajax調用wcf服務返回錯誤

var Type; 
var Url; 
var Data; 
var ContentType; 
var DataType; 
var ProcessData; 

function WCFJSON() { 

Type = "GET"; 
Url = "http://server.com/main/webservices/econnect.svc/getdata"; 

ContentType = "application/json; charset=utf-8"; 
DataType = "json"; varProcessData = true; 
CallService(); 
} 

function CallService() { 
$.ajax({ 
    type: Type, //GET or POST or PUT or DELETE verb 
    url: Url, // Location of the service 

    contentType: ContentType, // content type sent to server 
    dataType: DataType, //Expected data format from server 
    processdata: ProcessData, //True or False 
    success: function(msg) {//On Successfull service call 
     ServiceSucceeded(msg); 
    }, 
    error: ServiceFailed// When Service call fails 
    }); 
} 

function ServiceFailed(result) { 
    alert('Service call failed: ' + result.status + '' + result.statusText); 
    Type = null; 
    varUrl = null; 
    Data = null; 
    ContentType = null; 
    DataType = null; 
    ProcessData = null; 
} 
function ServiceSucceeded(result) { 
    if (DataType == "json") { 
     resultObject = result.GetUserResult; 

    for (i = 0; i < resultObject.length; i++) { 
     alert(resultObject[i]); 
    } 

    } 

} 

function ServiceFailed(xhr) { 
    alert("Error:" + xhr.responseText); 

    if (xhr.responseText) { 
     var err = xhr.responseText; 
     if (err) 
      error(err); 
     else 
      error({ Message: "Unknown server error." }) 
    } 

    return; 
} 

$(document).ready(
    function() { 
     WCFJSON(); 
    } 
+1

什麼是錯誤?! – 2015-02-23 19:12:37

+0

未找到端點 – 2015-02-23 20:23:49

回答

0

我認爲,這是由於語法錯誤:

varProcessData=true; 

應該是:

var ProcessData=true; 

其他你可以這樣評價這一行:

//processdata: ProcessData, //True or False 
相關問題