【发布时间】:2018-05-26 12:59:42
【问题描述】:
好的,我有这个 php 代码:
<!doctype html>
<html>
<body>
<?php
$q = intval($_GET['q']);
$con = mysqli_connect('localhost', 'root', '', 'testDB');
if(!$con){
die('Could not connect: '. mysqli_error($con));
}
mysqli_select_db($con, "testDB");
$query = "SELECT * FROM `aTable`;";
$result = mysqli_query($con,$query);
$row = mysqli_fetch_array($result);
echo $row[$q];
mysqli_close($con);
exit();
?>
</body>
</html>
我用 HTML 调用这个脚本:
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if(this.readyState == 4 && this.status == 200){
var Response = this.responseText;
console.log(Response);
}
};
xmlhttp.open("GET", "script.php?q=1", true);
xmlhttp.send();
}
但是,控制台记录
<!doctype html>
<html>
<body>
-3, -1, -2, 0, 2, 1, 2, 4, 5, 3, 4, 2, 4, 5, 6, 2, 3, 1, 3, 4, 1, -1, -3, -1
我不知道为什么,但它返回了这些我不想要的 HTML 标记(只有从 -3 到 -1 [带逗号] 的值)
如何删除(未闭合的)HTML 标签?
感谢所有回答!
【问题讨论】:
-
从您的文件中删除 HTML 标记。当然。
-
在文本编辑器中打开您的 PHP 文件。删除你不想要的。保存文件。 (注意:标签是“未关闭的”,因为您调用
exit()在关闭标签之前终止脚本。) -
真的有这样的问题吗?
标签: php html xmlhttprequest