1

I have this URL, that I supposedly should receive an XML from. So far I have this:

    function GetLocationList(searchString)
    {

  $.ajax({
    url: "http://konkurrence.rejseplanen.dk/bin/rest.exe/location?input=" + searchString,
    type: "GET",
    dataType: "html",
    success: function(data) {

    //Use received data here.
    alert("test");

    }
});

Tried to debug with firebug, but it doesn't go into the success method. Though, in DreamWeaver it is able to post a simple alert, which is inside the success method. I tried writing xml as dataType, but it doesn't work (in DreamWeaver) when I write alert(data). But it shows an alert with the entire XML, when I write html as dataType.

How do I get the XML correctly, and how do I parse and for example get the "StopLocation" element?

4

2 回答 2

2

尝试添加一个错误函数。

请参阅在此处输入链接描述

这将为您提供使用 Firefox 调试代码所需的所有信息。

$.ajax({
    url: "http://konkurrence.rejseplanen.dk/bin/rest.exe/location?input=" + searchString,
    type: "GET",
    dataType: "html",
    success: function(data) {

    //Use received data here.
    alert("test");

    },
    error: function(jqXHR, textStatus, errorThrown ){
      // debug here
    }
});
于 2013-04-18T10:39:47.093 回答
1

你需要先解析它,然后你可以搜索属性。像这样。

success: function(data) {
        var xml = $.parseXML(data)
        $(xml).find('StopLocation').each(function()
    {
        var name = $(this).attr('name');
        alert(name);
    }       
    );

这将为您提供每个 StopLocation 的名称。

希望这会有所帮助,您也可以对文档中的所有其他属性使用相同的方法。

于 2013-04-18T10:07:40.383 回答