Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/469.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.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
使用javascript显示xml rest数据时出错_Javascript_Xml - Fatal编程技术网

使用javascript显示xml rest数据时出错

使用javascript显示xml rest数据时出错,javascript,xml,Javascript,Xml,伙计们,我试图在HTML页面上显示一些xml数据,我发送REST请求并使用ajax获取响应,但是当我在DOM上附加元素时,我得到了“未定义”。这是xml文档 ` 米兰 伦巴第 罗马 拉齐奥 ` 这是调用的代码 $(document).ready(function(){ $.ajax({ type: "GET", dataType: "xml", url: "http://localhost:8080/RestService/webresources/entiti

伙计们,我试图在HTML页面上显示一些xml数据,我发送REST请求并使用ajax获取响应,但是当我在DOM上附加元素时,我得到了“未定义”。这是xml文档

`


米兰
伦巴第
罗马
拉齐奥
`
这是调用的代码

$(document).ready(function(){
$.ajax({
     type: "GET",
     dataType: "xml",
     url: "http://localhost:8080/RestService/webresources/entities.city",
     success: function(xml){
        var city;
        $(xml).find("cityPK").each(function(){
            city = $(this).attr("name"); 
            console.log(city);
            $("#city").append(city+ "<br />");
         });
     }
    });
});
$(文档).ready(函数(){
$.ajax({
键入:“获取”,
数据类型:“xml”,
url:“http://localhost:8080/RestService/webresources/entities.city",
成功:函数(xml){
瓦尔市;
$(xml).find(“cityPK”).each(function(){
城市=$(this.attr(“名称”);
控制台.日志(城市);
$(“#城市”)。追加(城市+”
); }); } }); });
我知道问题可能是因为异步操作,但我无法解决这个问题。
有什么想法吗?提前感谢

验证页面是否作为xml提供。在服务器返回给我的xml页面中,我必须把这个头放在哪里?我已经在ajax调用中添加了该标题,但它仍然不起作用@科尔姆
$(document).ready(function(){
$.ajax({
     type: "GET",
     dataType: "xml",
     url: "http://localhost:8080/RestService/webresources/entities.city",
     success: function(xml){
        var city;
        $(xml).find("cityPK").each(function(){
            city = $(this).attr("name"); 
            console.log(city);
            $("#city").append(city+ "<br />");
         });
     }
    });
});