【问题标题】:xhttp.send returning 404 not found but file existxhttp.send 返回 404 未找到但文件存在
【发布时间】:2018-04-10 09:48:43
【问题描述】:

请看图片,我在两个页面中调用相同的函数。

当我在没有任何参数的情况下在打开的页面中调用函数时,状态码为200,我得到结果correctly

但是当我在使用 GET 参数打开的页面中调用函数时,状态码是 404 并且我收到错误“Failed to load resource: the server responded with a status of 404 (Not Found)

我的功能是:

function myajax(method, api, data, callback){

var xhttp = new XMLHttpRequest();

xhttp.open(method, api, true);
xhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        callback(this.responseText);
    }
};

xhttp.send(data);
}

然后调用它:

myajax("POST", "../wp-content/themes/ad/config.php", "data="+data+"&api="+myapi, myCallBack);

【问题讨论】:

  • 显示响应和请求标头。
  • 我对 Wordpress 一无所知,所以这只是一个想法:你确定 Wordpress 接受这些参数吗?例如。也许它需要带有斜杠 (/data/value/api/value/) 或仅 (/dataValue/apiValue/) 的漂亮 URL,而不是带有问号和 & 符号的典型参数。
  • 是的,它接受了,但是,我精确地更改了 apiValue,但我的问题没有解决。

标签: php ajax get xmlhttprequest


【解决方案1】:

原因是数据负载过长。每当要发送的数据超出 config.php 文件中接收到的数据包大小时,该文件将不会响应请求,客户端会收到带有 404 标头的响应。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-15
    • 1970-01-01
    • 2022-01-06
    • 2018-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多