Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
对WCF Restful服务的JQuery异步xml GET请求失败_Wcf_Jquery - Fatal编程技术网

对WCF Restful服务的JQuery异步xml GET请求失败

对WCF Restful服务的JQuery异步xml GET请求失败,wcf,jquery,Wcf,Jquery,我有一个jqueryajax函数,它调用一个mywcfsrestweb服务。我的web服务调用另一个返回JSON的服务。我不想创建所有C#类并解析JSON响应并返回它。所以我只是创建了一个包含一个string属性的类,并将json作为该属性中的字符串阻塞,然后将其作为xml返回 在客户端,当我直接调用天气服务并返回JSON时,我实际上让客户端工作得非常好,并享受JQuery的自动解析。现在,我将数据类型更改为“xml”,它总是进入错误函数,没有有用的错误消息 function getWeathe

我有一个jqueryajax函数,它调用一个mywcfsrestweb服务。我的web服务调用另一个返回JSON的服务。我不想创建所有C#类并解析JSON响应并返回它。所以我只是创建了一个包含一个string属性的类,并将json作为该属性中的字符串阻塞,然后将其作为xml返回

在客户端,当我直接调用天气服务并返回JSON时,我实际上让客户端工作得非常好,并享受JQuery的自动解析。现在,我将数据类型更改为“xml”,它总是进入错误函数,没有有用的错误消息

function getWeather(location) {
    var requestURL = 'http://localhost:55120/Weather1.svc/Weather/' + location;
    return $.ajax({
        url: requestURL,
        type: 'GET',
        dataType: 'xml',
        error: function (xhr, status, errorThrown) {
            hideWeatherDiv();
            var jsonVal = $.parseJSON(xhr.responseText);
            $("#errorDiv").html('Response code: ' + xhr.status + '<br/>Response text: ' + jsonVal + '<br/>Status: ' +status + '<br/>Error thrown: ' + errorThrown);
        }
    });
}

var promise = getWeather(location);
promise.success(function (data) {
    alert('promise success');
    renderWeather(data);
    return;
});
函数getWeather(位置){
var requestURL=http://localhost:55120/Weather1.svc/Weather/“+位置;
返回$.ajax({
url:requestURL,
键入:“GET”,
数据类型:“xml”,
错误:函数(xhr、状态、错误抛出){
hidewatherdiv();
var jsonVal=$.parseJSON(xhr.responseText);
$(“#errorDiv”).html('响应代码:'+xhr.status+'
响应文本:'+jsonVal+'
状态:'+status+'
抛出的错误:'+errorworn]; } }); } var promise=getWeather(位置); 承诺.成功(功能(数据){ 警惕(“承诺成功”); 渲染器(数据); 返回; });
上面是函数和我对它的调用。正如我提到的,它正在向我的WCF服务发出请求,该服务正在呼叫气象服务。我可以在fiddler中看到我的WCF请求的响应,即它是有效的XML,但我无法在这里解析它