Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.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
从jquery获取xml数据_Jquery - Fatal编程技术网

从jquery获取xml数据

从jquery获取xml数据,jquery,Jquery,这是否可行?我有一个这样格式化的xml文件 <CoordinateData> <Country name="Australia"> <Marker> <LocationName>Port of Coff&#39;s Harbour</LocationName> <Longitude>153.0900</Longitude> <Latitude>

这是否可行?我有一个这样格式化的xml文件

<CoordinateData>
 <Country name="Australia">  
  <Marker>  
      <LocationName>Port of Coff&#39;s Harbour</LocationName>
      <Longitude>153.0900</Longitude>
      <Latitude>-30.1800</Latitude>
      </Marker>
  <Marker>      
      <LocationName>Port of Sydney</LocationName>
      <Longitude>151.1750</Longitude>
      <Latitude>-33.4500</Latitude>     
  </Marker>
  <Marker>      
      <LocationName>Port of Melbourne</LocationName>
      <Longitude>144.9450</Longitude>
      <Latitude>-37.8370</Latitude>     
  </Marker>
  </Country>
  <Country name="USA">
  <Marker>
    <LocationName>Natchez_MS</LocationName>
    <Longitude>91.4030</Longitude>
    <Latitude>31.5603</Latitude>
  </Marker>
  <Marker>
    <LocationName>Paducah_KY</LocationName>
    <Longitude>88.6010</Longitude>
    <Latitude>37.0833</Latitude>
  </Marker>   
</Country>

发布到目前为止您所拥有的。您使用的是什么开发环境?一般的想法是填充一个数据库,建立一个web服务,该服务使用AJAX在客户端页面中调用查询。jQuery对于这类事情非常有用。让我们知道您的数据库情况是什么样的..parseXML then.find('country[name=“”+country\u name+““]Marker')。每个(…)都有很多关于如何使用jquery解析xml的教程。。。。是的,这是可行的,并不困难
 $(document).ready(function () {
        var id;
        $.ajax({
            type: "GET",
            url: "OtherDataFiles/CoordinateData.xml",
            dataType: "xml",
            success: function(xml) {
                $(xml).find('Marker').each(function() {
                    if (id === "") {
                        id = $(this).attr('name');
                    } else {
                        id = id + "," + $(this).attr('name');
                    }


                });
            }
        });
        alert(id);
    });