AJAX无法发送到PHP

我试图将表单信息从index.html发送到output.PHP(两者都在同一目录中),但我收到此错误

Warning: UnkNown: Failed to open stream: No such file or directory in UnkNown on line 0

Fatal error: UnkNown: Failed opening required 'C:/xampp/htdocs/Tese_João/test-searchMysqL/output.PHP' (include_path='.;C:\xampp\PHP\PEAR') in UnkNown on line 0

如果您也可以帮助我,使用此代码我只能通过按ENTER或在搜索框外单击而不是只在搜索框中写入来获得AJAX的优势,任何人都知道如何解决这个问题?

index.html的:

<!DOCTYPE html>
<html>
<head>
<title> Escolha de molecula</title>

<script>
    function showUser(str) {
        if (str=="") {
            document.getElementById("ajax").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.status==200) {
                document.getElementById("ajax").innerHTML=xmlhttp.responseText;
            }
        }

        var txq=document.getElementById("textquery").value; 
        xmlhttp.open("POST","output.PHP?",true); 
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");            
        xmlhttp.send("textquery=" + txq); 
    }
</script>

</head>


<body>
    <h1 style="text-align:center;font-size: 60px"> 
        Search for molecule in our database 
    </h1>
    <hr>
        <p style="color:blue">
        <q>
            I have lived much of my life among molecules. They are good company.
        </q>
        George Wald
        </p>
    <hr>

    <p style="font-family:verdana">
        just write something in the search bar and it will retrieve it    <br>
        More information at: <a href="http://xldb.fc.ul.pt/" target="_blank">http://xldb.fc.ul.pt/</a>        
    </p>


    search: <input type="text"  id="textquery" onchange="showUser()" ><br> 

    </form>

    <br>

    <div id="ajax"><b>search results are displayed here</b></div> 
</body>
</html>

output.PHP

<?PHP

$con=MysqLi_connect("127.0.0.1","","ulchemd");
    // Check connection
if (MysqLi_connect_errno()) {
    echo "Failed to connect to MysqL: " . MysqLi_connect_error();
}

$pesquisa =MysqLi_real_escape_string($con,$_POST['textquery']);
$resposta = MysqLi_query($con,"SELECT * from target WHERE molecule.target_text like '%$pesquisa%' ");

echo " <b> Search results:";




echo "<table border='5'>
<tr>
<th>ID</th>
<th>target_type</th>
<th>name</th>
<th>text</th>
</tr>";


while($row = MysqLi_fetch_array($resposta)) { 
//este while vai buscar cada linha da tabela num ciclo como um cursor
  echo "<tr>";
  echo "<td>" . $row['tid'] . "</td>";
  echo "<td>" . $row['target_type'] . "</td>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['target_text'] . "</td>";
  echo "</tr>";
}

echo "</table>";

MysqLi_close($con);
?>

谢谢 :)

解决方法

在您的问题/代码中,index.html和output.PHP这两个文件中都没有这种类型的错误或异常.

根据错误,您尝试在代码中导入文件.所以请分享您的完整代码.

您也可以尝试更改output.PHP文件路径,如下所示.

xmlhttp.open("POST","http://localhost/projectName/output.PHP",true);

相关文章

IE6是一个非常老旧的网页浏览器,虽然现在很少人再使用它,但...
PHP中的count()函数是用来计算数组或容器中元素的个数。这个...
使用 AJAX(Asynchronous JavaScript and XML)技术可以在不...
Ajax(Asynchronous JavaScript and XML)是一种用于改进网页...
本文将介绍如何通过AJAX下载Excel文件流。通过AJAX,我们可以...
Ajax是一种用于客户端和服务器之间的异步通信技术。通过Ajax...