ajax调用wcf服务返回错误

时间:2015-02-23 19:08:13

标签: javascript jquery ajax web-services wcf

我正在尝试使用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();
    }

1 个答案:

答案 0 :(得分:0)

我认为,这是由于语法错误造成的:

varProcessData=true;  

应该是:

var ProcessData=true;

您可以通过其他方式评论此行:

//processdata: ProcessData, //True or False