所以,我有一些包含这个的PHP:
while($row = mysqli_fetch_array($result)) {
$wealth = $row['wealth'];
echo $wealth;
}
我指定'数据'的值变量,' x',当我发出警告(x)以下节目时:
<!DOCTYPE html>
<html>
<body>
136</body>
</html>
虽然我只想输出
136
这是我的javascript代码:
var username=localStorage.getItem('userName');
var highscore;
function getHighScore(user){
$.get("getScore.php?userName="+user,function(data){
console.log(data);
highscore=data;
alert(highscore);
});
}
getHighScore(username);
完整的PHP:
<!DOCTYPE html>
<html>
<body>
<?php
$username = strval($_GET['userName']);
$con = mysqli_connect('localhost','XXXX','XXXX','XXXX');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
} else {
$sql="SELECT * FROM users WHERE username = '".$username."'";
$result = mysqli_query($con,$sql);
while($row = mysqli_fetch_array($result)) {
$wealth = $row['wealth'];
echo $wealth;
}
}
mysqli_close($con);
//return $wealth;
?></body>
</html>
答案 0 :(得分:0)
替换以下代码
while($row = mysqli_fetch_array($result)) {
$wealth = $row['wealth'];
}
print_r($wealth);
我认为这是有效的。如果不在下面评论。
答案 1 :(得分:0)
从php中删除所有html代码。之前的一切?php和之后?
你正在从php返回所有的html并且javascript正在显示它。