jquery, xml

I have a webservice result below.

and I am trying to get value of <NetPrice></NetPrice> in jquery.

How can I do that? I have below jquery codes to get start.


<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">&lt;Status&gt;Completed&lt;/Status&gt;&lt;CustomerNumber&gt;335281&lt;/CustomerNumber&gt;&lt;OrderDate&gt;04-15-15&lt;/OrderDate&gt;&lt;OrderDetail&gt;&lt;Item id="0"&gt;&lt;Model&gt;&lt;![CDATA[AAS3602I]]&gt;&lt;/Model&gt;&lt;Quantity&gt;1&lt;/Quantity&gt;&lt;DealerPrice&gt;226.000&lt;/DealerPrice&gt;&lt;NetPrice&gt;226.000&lt;/NetPrice&gt;&lt;/Item&gt;&lt;/OrderDetail&gt;</string>

Open in new window


<script type="text/javascript">
    function unescapeHTML(escapedHTML) {
            return escapedHTML.replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&amp;/g, '&');
        } 
    function GetNetPriceByOrders() {
        var companyID = "066"
        var customerNo = "335281";
        var modelNo = "[AAS3602I]";
        var qty = "[1]";
        var orderDate = "1";
        var repNo = "SA7";
        var GetNetPriceJSon = "http://clientaccesstest.usa.com/wcf/orders/RestService/ProQuoteService/GetNetPrice";
        $(document).ready(function () {
            $.ajax({
                crossDomain: true,
                cache: false,
                type: "GET",
                async: false,
                dataType: "text", // "text/plain", //response format
                contentType: "text/plain", //request format                       
                url: GetNetPriceJSon + "(" + companyID + "," + customerNo + "," + modelNo + "," + qty + "," + orderDate + "," + repNo + ")",

                success: function (data) {
                     alert(data)

                },
                error: function (xhr, status, error) {
                    alert(xhr.responseText + " : error GetNetPriceJson from Orders");
                }
            });
        });
    }
</script>

Open in new window

LVL 1
ITsolutionWizardAsked:
Who is Participating?
 
RobOwner (Aidellio)Commented:
Once you've done the &lt; and &gt; replacement you can pass the string to jQuery that will automatically parse it into an object you can work with:

http://jsbin.com/xotaxu/1/edit?js,console

var rawxml = '<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">&lt;Status&gt;Completed&lt;/Status&gt;&lt;CustomerNumber&gt;335281&lt;/CustomerNumber&gt;&lt;OrderDate&gt;04-15-15&lt;/OrderDate&gt;&lt;OrderDetail&gt;&lt;Item id="0"&gt;&lt;Model&gt;&lt;![CDATA[AAS3602I]]&gt;&lt;/Model&gt;&lt;Quantity&gt;1&lt;/Quantity&gt;&lt;DealerPrice&gt;226.000&lt;/DealerPrice&gt;&lt;NetPrice&gt;226.000&lt;/NetPrice&gt;&lt;/Item&gt;&lt;/OrderDetail&gt;</string>';

var myxml = rawxml.replace(/&lt;/g,"<");
myxml = myxml.replace(/&gt;/g,">");

$(function() {
  var t = $(myxml);
  var f = t.find('netprice');
  console.dir(f.html()); // shows the value of the netprice element: 226.000
});

Open in new window

0
 
ITsolutionWizardAuthor Commented:
I try to get the value/result by

alert("Data?" + f);
but It is nothing...any ideas why?
0
 
ITsolutionWizardAuthor Commented:
so I try to replace the rawxml to the result of the web services.
and it returns null but I can see response in F12 screen.

is it because I need to return the object to string? Just not sure and need more helps.

 success: function (data) {
                        //var rawxml = '<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">&lt;Status&gt;Completed&lt;/Status&gt;&lt;CustomerNumber&gt;335281&lt;/CustomerNumber&gt;&lt;OrderDate&gt;04-15-15&lt;/OrderDate&gt;&lt;OrderDetail&gt;&lt;Item id="0"&gt;&lt;Model&gt;&lt;![CDATA[AAS3602I]]&gt;&lt;/Model&gt;&lt;Quantity&gt;1&lt;/Quantity&gt;&lt;DealerPrice&gt;226.000&lt;/DealerPrice&gt;&lt;NetPrice&gt;226.000&lt;/NetPrice&gt;&lt;/Item&gt;&lt;/OrderDetail&gt;</string>';
                        var rawxml = data;
                        var myxml = rawxml.replace(/&lt;/g, "<");
                        myxml = myxml.replace(/&gt;/g, ">");
                        $(function () {
                            var t = $(myxml);
                            var f = t.find('NetPrice');
                            alert(f.html()); // shows the value of the netprice element: 226.000
                        });
                    },
0
 
RobOwner (Aidellio)Commented:
Please post the results of:

console.dir(data);
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.