【问题标题】:ajax call to wcf service returning errorajax 调用 wcf 服务返回错误
【发布时间】:2015-02-23 19:08:13
【问题描述】:

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

【问题讨论】:

    标签: javascript jquery ajax web-services wcf


    【解决方案1】:

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

    varProcessData=true;  
    

    应该是:

    var ProcessData=true;
    

    你可以用其他方式评论这一行:

    //processdata: ProcessData, //True or False
    

    【讨论】:

      猜你喜欢
      • 2012-08-11
      • 2012-08-31
      • 2011-01-04
      • 2011-09-25
      • 1970-01-01
      • 2014-03-04
      • 1970-01-01
      • 2016-09-17
      • 1970-01-01
      相关资源
      最近更新 更多