繁体   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