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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.