Php 我们可以使用xmlhttp.open()吗;在同一文件中
我尝试使用w3school提供的这些代码,但我遇到了一些问题 我的第一个文件:Php 我们可以使用xmlhttp.open()吗;在同一文件中,php,ajax,Php,Ajax,我尝试使用w3school提供的这些代码,但我遇到了一些问题 我的第一个文件: <script> function showHint(str) { var xmlhttp; if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest)
<script>
function showHint(str)
{
var xmlhttp;
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getresult.php?q="+str,true);
xmlhttp.send();
}
</script>
<?php
echo "First name: <input type=\"text\" id=\"txt1\" onkeyup=\"showHint(this.value)\" />";
echo "<p>Suggestions: <span id=\"txtHint\"></span></p>";
?>
因为我在我的服务器上上传了这两个文件,所以它不起作用,但在我的计算机(localhost)上运行时可以起作用
谢谢。你可以用这个
if (isset($_GET['q'])) {
//getresult.php contents
}
else {
//first file contents
}
什么不起作用?具体点。
xmlhttp.open("GET","getresult.php?q="+str,true);
if (isset($_GET['q'])) {
//getresult.php contents
}
else {
//first file contents
}