i would like to access xml node values via javascript but i get error

hi i have an xml , and just want to access test value below via javascript,

but it fails to display the value ,below is my page , could you help me what i am missing here?


<?xml version="1.0" encoding="utf-8" ?>
<test>3</test>



  <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LongPoll.aspx.cs" Inherits="LongPollingSample.LongPoll" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    
     <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
   

    <script>

        $.ajax({
            type: "GET",
            url: "Data.xml",
            dataType: "xml",
            success: function (xml) {
                // Parse the xml file and get data
                var xmlDoc = $.parseXML(xml),
                    $xml = $(xmlDoc);

                $v1 = $xml.find("test");


                alert($xml.find("test").value);

//$xml.find('note').each(function () {
                //    $("#test").append($(this).text() + "<br />");
                //});
            }
        });

    </script>
    <script>
        
        //var intervalId = setInterval(function () {


        //    $.ajax({
        //        url: "server", success: function (data) {
        //            //Update your dashboard gauge
        //            //salesGauge.setValue(data.value);
        //        }, dataType: "json"
        //    });
        //}, 30000);

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <p id="someElement"></p>
    </div>
    </form>
</body>
</html>

Open in new window

nicedoneAsked:
Who is Participating?
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.

Julian HansenCommented:
Try this
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
  $(function() {
    $.ajax({
      type: "GET",
      url: "Data.xml",
      dataType: "xml",
      success: function (xml) {
        var test = $(xml).find('test').text();
        $('#result span').html(test);
      }
    });
  });
</script>
</head>
<body>
<form id="form1">
  <div>
    <p id="someElement"></p>
    </div>
</form>
<div id="result">XML Value: <span></span></div>
</body>
</html>

Open in new window

Assumes XML file
<?xml version="1.0" encoding="utf-8" ?>
<test>3</test>

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
nicedoneAuthor Commented:
thanks
0
Julian HansenCommented:
You are welcome.
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
JavaScript

From novice to tech pro — start learning today.

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.