加载XML并获取标记.从php更改为javascript


Load XML and get tag. Change from php to javascript

我有一个服务器端脚本,但现在我希望它在客户端运行,所以我想从php转换为javascript。我真的不擅长js,所以请帮忙。

此处的Php代码:

    function getAlexaRank($theUrl)
    {
        $alexa_url = "http://data.alexa.com/data?cli=10&dat=snbamz&url=" . $theUrl;
        $doc = new DOMDocument();
        $doc->load($alexa_url);
        $popularities = $doc->getElementsByTagName("POPULARITY");
        foreach($popularities as $popularity)
        {
            return $popularity->getAttribute('TEXT');
        }
        return "-1";
    }

请参阅以下链接以使用js 实现它

http://www.hiteshagrawal.com/javascript/javascript-parsing-xml-in-javascript