【发布时间】:2017-09-08 08:06:06
【问题描述】:
我想用一个简单的程序测试 php-Ajax。我正在使用 html 和 php 文件都存储在同一个目录 (/var/www/html) 中。当我单击按钮时,它在控制台中显示以下错误。 XML 解析错误:找不到根元素位置。 ??
html 文件
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<title> Ajax testing </title>
<script type="text/javascript">
function load(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("result").innerHTML = this.responseText;
}
};
xmlhttp.open("GET", "simple.php" , true);
xmlhttp.send();
}
</script>
</head>
<body>
<button onclick="load();">Click here</button>
<div id="result"> </div>
</body>
</html>
php 文件
<?php
echo "Hello";
?>
这段代码有什么问题?
【问题讨论】:
标签: javascript php ajax xml