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($开发者_JS百科(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
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.
result = xmlIn.getElementsByTagName("Result")[0]; $('#tb_actualvsindexedbing_indexed').val($(result.getElementsByTagName("Value")[0]).text());
element = element; elements = array of elements
精彩评论