分前台调用html文件与后台php文件。
1.ajax.php文件,其他.py,.js等文本都可,有输出即可。
<?php echo 111;
2.index.html
<html>
<body onload="show()">
<script>
var xmlhttp = false;
if (window.XMLHttpRequest) { //Mozilla、Safari等浏览器
xmlhttp = new XMLHttpRequest();
}
else if (window.ActiveXObject) {//IE浏览器
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}//try
}//if
function show(){
xmlhttp.open('get','ajax.php?do=1',true);
xmlhttp.onreadystatechange=function(){
if((xmlhttp.readyState==4)&&(xmlhttp.status==200)){
document.getElementById("finished").innerHTML=xmlhttp.responseText;
}//if
}//function
xmlhttp.send(null);
}//show
</script>
<div id="finished"></div>
</body>
</html>