Search code examples
phpajaxgetxmlhttprequest

xhttp.send returning 404 not found but file exist


please look at the picture, I'm calling same function in two page.

when I call function within the page opened without any parameter, status code is 200 and I get result correctly.

but when I call function within the page opened with GET parameter, status code is 404 and I get error "Failed to load resource: the server responded with a status of 404 (Not Found)"

my function is:

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);
}

and call that with:

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

my image


Solution

  • The reason for this was a lengthy data payload. Whenever the data to be sent is goes beyond the size of packets received in the config.php file, this file will not respond to request and the client receives a response with a 404 header.