无法获取所有POST成功xml数据 [英] Cannot get all POST Success xml data

查看:76
本文介绍了无法获取所有POST成功xml数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取xml标记结果并将其加载到地图上,但是当我发出警报时,我在变量中得到的发布结果是这样的:

I'm trying to take my xml marker results and load them onto a map, however the post result I get in my variable when I alert is this:

已加载数据:[对象XMLDocument]

Data Loaded: [object XMLDocument]

这是我的代码的样子:

function SendData() {

//get data from inputs

            $.ajax({
                type: "POST",
                url: "MapSearchxml.php",
                data: {
                    dataFromDate: FromDate,
                    //some more data
                    dataHasPatio: HasPatio
                },
                beforeSend: function (html) { // this happens before actual call
                },
                success: function (html) { // this happens after we get results

                alert("Data Loaded: " + html);

                }
            });
}

在Firebug中,帖子响应如下所示:

In Firebug, the post response looks like this:

<markers><marker id="1" lat="48.153938" lng="17.108459" /></markers>

我试图像这样将数据类型设置为xml:

I tried setting the datatype to xml like this:

                success: function (html) { // this happens after we get results
                alert("Data Loaded: " + html);
                }, 
                dataType: 'xml'
            });
}

但是没有任何变化.

这是我的xml php代码:

Here's my xml php code:

$result = mysql_query($query);
if (!$result) {
  die('Invalid query: ' . mysql_error());
}


header("Content-type: text/xml");

echo '<markers>';

while ($row = @mysql_fetch_assoc($result)){
  echo '<marker ';
  echo 'id="' . parseToXML($row['ID']) . '" ';
  echo 'lat="' . parseToXML($row['LAT']) . '" ';
  echo 'lng="' . parseToXML($row['LNG']) . '" ';
  echo '/>';
}

echo '</markers>';

推荐答案

当将XML对象附加到文本字符串并在警报中显示数据时,这是浏览器处理XML对象的方式.您的ajax调用看起来正常.

This is how the browser handles XML objects when appending them to a text string and displaying the data in an alert. Your ajax call looks like it's working.

您可以尝试更改:

    success: function (html) { // this happens after we get results
       alert("Data Loaded: " + html);
    }, 

只是:

    success: function (html) { // this happens after we get results
       console.log(html);
    }, 

,然后在JavaScript控制台中查看该对象. 或:

and view the object in the JavaScript console. or:

    success: function (html) { // this happens after we get results
        var xmlString = (new XMLSerializer()).serializeToString(html);
        alert("Data loaded: " + xmlString);
    }, 

这篇关于无法获取所有POST成功xml数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆