2017-10-29 89 views
1

请看图片,我在两页中调用相同的函数。xhttp.send返回404找不到,但文件存在

当我打开没有任何参数的页面内调用函数时,状态码是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); 

my image

+0

显示响应和请求标头。 – Scriptonomy

+0

我对Wordpress一无所知,所以这只是一个想法:你确定Wordpress接受这些参数?例如。也许它需要带有斜杠(/ data/value/api/value /)的漂亮URL或者仅仅是(/ dataValue/apiValue /)而不是带有问号和&符号的典型参数。 – Tom

+0

是的,它接受了,但是,我精确地更改了apiValue,但我的问题没有解决。 –

回答

1

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