使用AJAX返回[文档对象]的XML检索,如何获取内容? [英] XML retrieval with AJAX returning [Document Object], How do I get the content?

查看:57
本文介绍了使用AJAX返回[文档对象]的XML检索,如何获取内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问了一个与昨天类似的问题,但此后在此问题上取得了进展. 现在,所有阻碍我前进的方法就是弄清楚如何将这种成功的反应变成切实的东西.现在,我充其量只能得到"[Document Object]"的回报.在尝试检索字段的responseText时,我得到了未定义".

I asked a question similar to this yesterday, but have since made progress on the problem. Now, all that stands in my way is figuring out how to turn this success response into something tangible. Right now I'm getting a return of "[Document Object]" at best. In attempting to retrieve the responseText of the field I was getting "undefined".

对于我来说,这似乎是对该协议的核心误解,因此,如果有人可以解决此问题并向我提供一个教程资源,我会非常感激.

This appears to be a core misunderstanding of this protocol on my part, so if anyone can solve this problem and provide me with a tutorial resource to move forward with i'd very much appreciate it.

var returnval;
$.ajax({
    type: "GET",
    url: "https://www.mychoicetechnologies.com/Services/FMSUtilities.asmx/GetServerDate",
    data: "{}",
    contentType: "application/xml; charset=utf-8",
    success: function (msg) {

        document.getElementById('area').innerHTML = "Success! Retrieved a server response using AJAX.<br>";
        alert(msg);
    },
    error: function (xhr, status, error) {
        document.getElementById('area').innerHTML = "1." + error + "<br>";
        document.getElementById('area').innerHTML += "2." + xhr + "<br>";
        document.getElementById('area').innerHTML += "3." + status + "<br>";
        document.getElementById('area').innerHTML += "The script has failed.";
    }
});

此致

-西恩

我已经找到了想要的解决方案.

I've discovered the solution I was looking for.

msg.getElementsByTagName("string")[0].childNodes[0].nodeValue;

我必须跳过xml节点才能获得我想要的字段的值. http://www.w3schools.com/dom/dom_nodes_get.asp

I had to jump through the xml nodes to get to the value of the field I was looking for. http://www.w3schools.com/dom/dom_nodes_get.asp

推荐答案

最好使用console.log然后发出警报,像这样:

It's better to use console.log then alert, like that :

$.ajax({
  type: "GET",
  url: "https://www.mychoicetechnologies.com/Services/FMSUtilities.asmx/GetServerDate",
  data: "{}",
  contentType: "application/xml; charset=utf-8", 
  success: function (msg) 
  {     

     document.getElementById('area').innerHTML = "Success! Retrieved a server response using AJAX.<br>";
     console.log(msg);
  },
  error: function (xhr, status, error)
  {        
     document.getElementById('area').innerHTML =  "1." + error +   "<br>";
     document.getElementById('area').innerHTML += "2." + xhr +     "<br>";
     document.getElementById('area').innerHTML += "3." + status +  "<br>";
     document.getElementById('area').innerHTML +=           "The script has failed.";
  }
});

如果您使用的是Google Chrome浏览器,请使用快捷键"ctrl + shift + j",然后重试查询.

If you use Google Chrome, use the shortcut "ctrl + shift + j", and retry you query.

这篇关于使用AJAX返回[文档对象]的XML检索,如何获取内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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