簡體   English   中英

ajax調用wcf服務返回錯誤

[英]ajax call to wcf service returning error

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

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

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

varProcessData=true;  

應該:

var ProcessData=true;

您可以通過其他方式評論此行:

//processdata: ProcessData, //True or False

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM