2011-03-10 41 views
1

我是一個在網絡開發初學者,所以我在這個問題上很難,我試圖讓一個網站,從任何玩家從一個遊戲我玩,它的工作原理是在文本框中輸入玩家的名字,然後當你點擊'OK'時,它調用一個js函數,調用一個php函數,在遊戲網站api上獲取xml,然後打印結果,當使用我的本地服務器時(apache)一切運行順利,沒有錯誤,但是當我上傳文件到我的主機變量沒有被傳遞,我不知道爲什麼,這是我的網站www.statsofnewerth.sevencut.com.br /playerStats.php,只需在「Alcartur」框中鍵入我的用戶名,然後它應該返回我的一個統計數據,但它只是空白的,我把一個警報顯示nick變量和返回值,這裏是代碼:PHP:價值沒有通過網址

playerStats.php

<div class="search-panel"> 
<label>Search for player:</label> 
<input name="playerName" id="txt_playerName" type="text" value="" size="20" maxlength="20" /> 
<input name="btnPlayerSearch" type="button" value="Ok" onclick="requestPlayerData()" /> 
</div> 

form.js

function requestPlayerData(){ 
    var img = new Image(); 
    img.src = "src/wait.gif"; 
    document.getElementById('wait-panel').innerHTML = ""; 
    document.getElementById('wait-panel').appendChild(img); 
    var nickname = document.getElementById('txt_playerName').value; 
    ajaxFunction(nickname); 
    } 

    function ajaxFunction(nickname){ 
    $('#wait-panel').load("httpRequest.php?nickname="+nickname, function(html){ 
    alert(html); 
}); 
} 

和httpRequest.php

<?php 
header('Content-type: application/xml'); 
$q = $_GET['nickname']; 
echo 'nickname'.$q; 
$sxe = simplexml_load_file('http://xml.heroesofnewerth.com/xml_requester.php?f=player_stats&opt=nick&nick[]='.$q); 
$result = $sxe->xpath("//*[@name='rnk_amm_team_rating']"); 
print_r($result); 
?> 

只是記住的是,在我的本地服務器它的工作原理。

Sry對於任何英語錯誤,這不是我的第一語言。提前致謝。

+0

那麼警報就會顯示爲空白,或根本沒有?你有一個指向你本地服務器的基本標籤集合嗎?我今天用ajax調用了這個問題! –

+0

這是空白的,只有硬編碼的字符串,沒有,沒有基地標籤。 –

回答

1

是根據數據加載的?

$sxe = simplexml_load_file('http://xml.heroesofnewerth.com/xml_requester.php?f=player_stats&opt=nick&nick[]='.$q); 
var_dump($sxe);die(); 
+0

是的,由於變量暱稱是空的,請求返回一個錯誤,當有一些無效字符時返回這個錯誤。 「object(SimpleXMLElement)#1(1){[」error「] => string(39)」格式化帳戶時發生問題。「}」 –

1

確保您的httpRequest頁面正在返回正確的數據。我不認爲這是。

<?php 
header('Content-type: application/xml'); 
$q = $_GET['nickname']; 
echo 'nickname'.$q; 
$sxe = simplexml_load_file('http://xml.heroesofnewerth.com/xml_requester.php?f=player_stats&opt=nick&nick[]='.$q); 
$result = $sxe->xpath("//*[@name='rnk_amm_team_rating']"); 
//print_r($result); // I don't think this can work? could be wrong 

echo $result[0]; // this returns the first xpath match and outputs the value of the node, which is the "rnk_amm_team_rating" thing 

// since this php says it returns XML (the header line), it should either do so or get rid of the header. 
?> 
+0

print_r($ result);正在工作,它以可讀的方式打印整個陣列,就像我說的那樣,它在我的本地主機服務器上完美運行,它不在遠程服務器(hostgator)上工作,並且它不會在遠程返回正確的數據,因爲回聲'綽號' $ q;顯示它是空白的,因此http://xml.heroesofnewerth.com/xml_requester.php?f=player_stats&opt=nick&nick[]='.$q網址不完整。 –

0

傢伙我找到了解決辦法,即使我是把遠程服務器,我認爲當我acessed現場有人用我的電腦從一些緩存一些舊的文件(它甚至意義上的文件?),還是主持人有些問題,我不知道,但現在我在網上做了一個刷新,並且它正常工作,如果有人對我想聽到的事情有任何想法。謝謝問題解決了。