weixin_33674437 2017-02-02 15:33 采纳率: 0%
浏览 14

“ xml查找”不是功能

I currently have the following ajax call which runs successfully:

$.ajax({
            url: "services/orders/<%=OrderServices.Action.BULK_SUPPLIER_DISCOUNT%>",
            data: params,
            complete: function(xhr) {
                if (ajax.fullCheck(xhr, "delete your selected item")) {
                    unsavedChanges = false;
                }
                var xml = xhr.responseXML;
            updateAutoTotalsFromXml(xml);

            }
        });

variable "xml" returns:

<Response><Totals><FixedCost>0</FixedCost><FixedPrice>0</FixedPrice><VarCost>70.4900</VarCost><VarPrice>224.87</VarPrice></Totals><Success/></Response>

however when i get to here, i get the error Uncaught TypeError: xml.find is not a function.

function updateAutoTotalsFromXml(xml) {
        console.log(xml);
        curFixedCost = parseFloat(xml.find("FixedCost").text());
        curFixedPrice = parseFloat(xml.find("FixedPrice").text());
        curVarCost = parseFloat(xml.find("VarCost").text());
        curVarPrice = parseFloat(xml.find("VarPrice").text());
    }

ideas?

  • 写回答

1条回答 默认 最新

  • weixin_33670786 2017-02-02 15:40
    关注

    According to jQuery.parseXML():

    Parses a string into an XML document.

    jQuery.parseXML uses the native parsing function of the browser to create a valid XML Document. This document can then be passed to jQuery to create a typical jQuery object that can be traversed and manipulated.

    You can convert the xml to a jqueryObject and only after you can use the find function:

    var xml = '<Response><Totals><FixedCost>0</FixedCost><FixedPrice>0</FixedPrice><VarCost>70.4900</VarCost><VarPrice>224.87</VarPrice></Totals><Success/></Response>';
    
    function updateAutoTotalsFromXml(xml) {
      console.log(xml);
      var xmlDoc = $.parseXML(xml);
      var jqObj = $(xmlDoc);
      curFixedCost = parseFloat(jqObj.find("FixedCost").text());
      curFixedPrice = parseFloat(jqObj.find("FixedPrice").text());
      curVarCost = parseFloat(jqObj.find("VarCost").text());
      curVarPrice = parseFloat(jqObj.find("VarPrice").text());
    
      console.log('curFixedCost: ' + curFixedCost +
                  ' curFixedPrice: ' + curFixedPrice +
                  ' curVarCost: ' + curVarCost +
                  ' curVarPrice: ' + curVarPrice)
    }
    
    
    updateAutoTotalsFromXml(xml);
      
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法