我目前正在試圖做一個網站,我把信息放在我的html端,它將信息發送到php文件,並從另一個網站獲取信息,具體取決於您在html端放置的內容。如何將一個變量從一個php文件傳遞給一個javascript文件?
爲了使這更清楚,這是它如何工作的:
- 你把你的用戶名在HTML站點(JavaScript代碼 是)。
- 然後它將您的用戶名發送到php文件。
- php文件獲取信息,將其放入鏈接並請求它。
- 它從這個請求抓取信息(高分頁)。
- 這是停止的地方。
我不知道如何將信息返回給我的JavaScript文件。
這是我的代碼:
HTML/JavaScript頁面:
<html>
<head>
<script type="text/javascript" src="./aloticcalc_files/jquery.min.js"></script>
</head>
<body>
<script>
function test() {
var username = "Exzib";
window.location.href = "grabinfo.php?username=" + username;
}
</script>
</body>
</html>
這是我的PHP文件:(grabinfo.php)
<html>
<head>
</head>
<?php
$username = $_GET['username'];
include_once('simple_html_dom.php');
if(isset($_GET['name'])) {
$html = file_get_html('https://alotic.com/hs/?name='.$username);
$xp = $html->find('td', 10);
$formatxp = $result=str_replace(array('$',',','.',' '),'',$xp);
echo $formatxp;
}
?>
<body>
</body>
</html>
那麼,如何進行發送$formatxp
到我的JavaScript?
感謝
'var javascript_var ='<?php echo $ formatxp; '>'' – adeneo