【问题标题】:The server responded with a status of 404 using ajax服务器使用 ajax 以 404 状态响应
【发布时间】:2019-04-11 13:36:28
【问题描述】:

我尝试创建一个对 php 脚本的简单 AJAX 调用。

request.js

var xhr = new XMLHttpRequest();
xhr.open('GET', './assets/script/api/sample.php');

xhr.onreadystatechange = function() {
    if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status <= 207)) {
        console.log(xhr.responseText);
    }
}

xhr.send();

示例.php

<?php echo "Hello World"; ?>

错误:

加载资源失败:服务器响应状态为 404 (未找到)(localhost:7456/assets/script/api/sample.php)

【问题讨论】:

  • /assets/script/api/sample.php sample.php 的正确路径吗?
  • 嗨@Krissy,请检查sample.php 路径和文件名
  • 路径正确。
  • 在浏览器地址中输入http://localhost:7456/assets/script/api/sample.php会得到什么
  • 你能在改变路径的服务器上有一个重写规则吗?检查访问日志。

标签: javascript php ajax cocos2d-js


【解决方案1】:

最近解决了这个问题。 php 文件应该放在 build 文件夹中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-30
    • 2020-05-29
    • 1970-01-01
    • 1970-01-01
    • 2021-07-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多