2012-08-30 35 views
0

我有一個服務器端腳本,但現在我希望它在客戶端運行,所以我想從PHP轉換爲JavaScript。我真的不擅長js,請幫忙。加載XML並獲取標籤。從PHP更改爲javascript

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"; 
    } 

回答