0

I am trying to parse the following XML with javascript:

<?xml version='1.0' encoding='UTF-8'?>
<ResultSet>
    <Result>
        <URL>www.asd.com</URL>
        <Value>10500</Value>
    </Result>
</ResultSet>

The XML is generated by a PHP script to get how many pages are indexed in Bing.

My javascript function is as follows:

function bingIndexedPages() {
    ws_url = "http://archreport.epiphanydev2.co.uk/worker.php?query=bingindexed&domain="+$('#hidden_the_domain').val();
    $.ajax({
        type: "GET",
        url: ws_url,
        dataType: "xml",
        success: function(xmlIn){
            alert('success');
            result = xmlIn.getElementsByTagName("Result");
            $('#tb_actualvsindexedbing_indexed').val($(result.getElementsByTagName("Value")).text());
            $('#img_actualvsindexedbing_worked').attr("src","/images/worked.jpg");          
        },
        error: function() {$('#img_actualvsindexedbing_worked').attr("src","/images/failed.jpg");}
    });
}

The problem I'm having is firebug is saying: 'result.getElementsByTagName is not a function'

Can you see what is going wrong?

Thanks

1
  • Well have you looked at "xmlIn" with Firebug to see what it is? Commented Mar 15, 2010 at 11:00

2 Answers 2

1

I actually just fixed it, what I was doing wrong was when I was trying to set the value of '#tb_actualvsindexedbing_indexed' I was not telling it to use the first entry of the xml, and was just passing it the entire object.

$('#tb_actualvsindexedbing_indexed').val($(result[0].getElementsByTagName("Value")).text());

Thanks for the help anyway.

Sign up to request clarification or add additional context in comments.

2 Comments

$('#tb_actualvsindexedbing_indexed').val($(result[0].getElementsByTagName("Value")[0]).text()); ??
That was what I altered to make it work. Basically just added the [0]
0

result = xmlIn.getElementsByTagName("Result")[0]; $('#tb_actualvsindexedbing_indexed').val($(result.getElementsByTagName("Value")[0]).text());

element = element; elements = array of elements

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.