weixin_33694620 2017-03-03 14:23 采纳率: 0%
浏览 22

Javascript [对象元素]

I am trying to get some xml datas from webservice. I can access all data but i cannot get one by one. I want write data to div that has id "code". It writes [object Element]. What i have to do?

<script type="text/javascript">
        $(document).ready(function () {
            var returnValue = localStorage.getItem("returnValue");
            var userName = localStorage.getItem("userName");
            alert("Hello" + userName);
            var wsUrl = "http://xxx=GetStocks";

            var soapRequest =
                '<?xml version="1.0" encoding="utf-8"?>\
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"\ xmlns:xsd="http://www.w3.org/2001/XMLSchema"\ xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">\
  <soap:Body>\
    <GetStocks xmlns="http://sales.xxx.org/">\
      <token>' + returnValue + '</token>\
    </GetStocks>\
  </soap:Body>\
</soap:Envelope>';

            $.ajax({
                type: "POST",
                url: wsUrl,
                contentType: "text/xml",
                dataType: "xml",
                data: soapRequest,
                success: processSuccess,
                error: processError
            });
        });

        function processSuccess(data, status, req) {
            if (status == "success") {
                var stocks = $(req.responseXML).find("pStockInfo");
                var codes = $(req.responseXML).find("Code");
                var stocksCount = stocks.length;

                $("#code").text(codes[0]); //Here i want first code.               
            }
        }

        function processError(data, status, req) {
            alert(req.responseText + " " + status);
        }
    </script>

enter image description here

Xml Data

enter image description here

I want get first code "FO19428"

  • 写回答

3条回答 默认 最新

  • larry*wei 2017-03-03 14:30
    关注

    You can use jQuery.eq()

     var codes = $(req.responseXML).find("Code");
     var firstCode = codes.eq(0).text(); 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗