javascript - 本地主机上出现奇怪的 404 错误

标签 javascript php html mysql

所以我有一个 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)上,SriMerusrimeru 不是同一件事;它们区分大小写。

因此,要么将文件夹重命名为全部小写字母,要么将 srimeru/forumSubmit.php 更改为 SriMeru/forumSubmit.php

关于javascript - 本地主机上出现奇怪的 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25539106/

相关文章:

javascript - 如何检查名称属性作为数组的复选框列表中是否至少选中了一个复选框

PHP:将所有字符转换为 HTML 实体

javascript - 如果存在验证错误,则保持单选按钮处于选中状态

javascript - <ul> <li> 列表项添加onclick

javascript - Angular js 预期响应包含对象,但出现数组类型错误

php - Laravel 4.2 - 仅选择基于另一个查询的行数为 0 的行

html - Bootstrap 导航栏在最小化浏览器时不起作用

Javascript - 如何检测两个数组的差异

javascript - 使用数组和 for 循环获取

javascript - 每个 then() 都应该返回一个值或抛出 Firebase 云函数