0

我正在用 Angular 编写一个 Web 应用程序,这段代码旨在从服务器获取测试 XML 数据作为文本。我正在使用 Angular 的 $http 服务从服务器发送 GET 请求。变量 'xmlData' 在 $http 块内被更改,但在该块之外,它的值仍然是默认值。这是代码:

this.getData = function() {
        var xmlData = "Default";
        var xmlDoc;
        // send an http GET request for the XML text data

        $http.get('http://localhost:1337/testXML.txt').success(function(data) {
            xmlData = data;
            if (xmlData == null) {
                alert("Data Error Occurred");
            }
        // here, 'xmlData' contains the correct information.
        }).
        error(function() {
            alert("HTTP Error Occurred");
        });

        // once the above $http block ends, the xmlData has the default value.          
        return xmlData;
}

那么这只是一个愚蠢的范围问题吗?还是我错误地使用了 Angular 的 $http 服务?谢谢!

4

1 回答 1

0

我认为没有某种解析器就不能像 JSON 那样直接插入 XML。

查看这个在 AngularJS 中处理 XML 的问题:如何在 AngularJS 中处理 XML 服务?

具体检查这些模块/插件以提供帮助:

于 2013-07-11T21:12:44.983 回答