所以我有一个 mySQL 数据库,并将它连接到一些 php 和 html 文件。我的 php 文件位于 localhost 文件夹中。当我运行我的测试 html 文件(也在我的 localhost 文件夹中)时,找到该文件没有问题,但是当我的 localhost 文件夹中有一个名为“SriMeru”的子文件夹时,我的实际 html 文件包含格式设置和其他内容最终的php文件,html文件无法找到php文件。以下是 html 文件中的一些代码:
<div id="mmargin" style="background-color:#F1ECDF;height:810px;width:600px;float:left;">
<p id = "myDiv">no</p>
<script>
function loadPHPDoc(str){
var xmlhttp;
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("myDiv").innerHTML=xmlhttp.responseText;
}
else{
document.getElementById("myDiv").innerHTML="failure";
}
}
xmlhttp.open("POST","srimeru/forumSubmit.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
var sender = "q=" + str;
xmlhttp.send(sender);
}
</script>
<p>
Message <input type= "text" id="messbox">
<button type= "button" onclick="loadPHPDoc(document.getElementById('messbox').value)">input</button>
</p>
</div>
这是我的 php 文件代码:
<?php
$q = $_POST["q"];
$messData = mysqli_connect("localhost", "root", "chendu", "SriMeru");
if (mysqli_connect_errno()){
echo "Failed to connect to Server";
}
$sql = "INSERT INTO messages VALUES ('".$q."')";
mysqli_query($messData, $sql);
echo "<p>success</p>";
mysqli_close($messData);
?>
html 文件中的其他地方,我有一些奇怪的格式,涉及字幕和计时器,我不知道这是否会弄乱事情。
最佳答案
"but when i have a subfolder within my localhost folder called "SriMeru" where i have my actual html file"
您说您的文件夹名为SriMeru
在许多系统(包括 UNIX/LINUX)上,SriMeru
和 srimeru
不是同一件事;它们区分大小写。
因此,要么将文件夹重命名为全部小写字母,要么将 srimeru/forumSubmit.php
更改为 SriMeru/forumSubmit.php
关于javascript - 本地主机上出现奇怪的 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25539106/