XMLHttpRequest request to php page gives server 404 ( page not found)
hello all
im doing simple XMLHttpRequest request to the server tested both in apache 2.2 and
lighttpd and they both gives me the same results
i have client side code that lookes liks this
index.php
Code:
var rqo;
function req(d)
{
if (d != "")
{
document.getElementById("details_data").innerHTML = "Fetching Data ...." ;
rqo = createRequestObject();
var qry = encodeURIComponent(d);
rqo.open('GET',qry,true); //<< also tried false here ...
rqo.onreadystatechange = handleDetailsHttpResponse ;
rqo.send(null);
return false;
}
}
function handleDetailsHttpResponse() {
var results = "";
if (rqo.readyState == 4) {
results = rqo.responseText;
document.getElementById("details_data").innerHTML = results;
}
}
in the d variable the value is :
index.php?Action=1&data_input=059652983X&data_category=All
now in the lighttpd for example im getting the error that file is not found 404
Code:
2009-02-07 22:40:15: (response.c.453) -- logical -> physical
2009-02-07 22:40:15: (response.c.454) Doc-Root : /var/www/
2009-02-07 22:40:15: (response.c.455) Rel-Path : /index.php?Action=1&data_input=059652983X&data_category=All
2009-02-07 22:40:15: (response.c.456) Path : /var/www/index.php?Action=1&data_input=059652983X&data_category=All
2009-02-07 22:40:15: (response.c.473) -- handling physical path
2009-02-07 22:40:15: (response.c.474) Path : /var/www/index.php?Action=1&data_input=059652983X&data_category=All
2009-02-07 22:40:15: (response.c.530) -- file not found
2009-02-07 22:40:15: (response.c.531) Path : /var/www/index.php?Action=1&data_input=059652983X&data_category=All
2009-02-07 22:40:15: (response.c.116) Response-Header:
HTTP/1.1 404 Not Found
Content-Type: text/html
Content-Length: 345
Date: Sat, 07 Feb 2009 20:40:15 GMT
Server: lighttpd/1.4.19
but the file is there for sure !!! this is the file im doing the request form ..
can someone please explain me what im doing wrong ?
Thanks
Re: XMLHttpRequest request to php page gives server 404 ( page not found)
If you are getting a 404, that means that the file does not exist at the path that the code is seeing...period. Somewhere, somehow, the source code cannot see the relative path as you think it is.
I would suggest using JavaScript's alert() function to show the d variable right before processing AJAX's open() method. Then, compare that path with the path of the actual loaded document in the browser window.
Re: XMLHttpRequest request to php page gives server 404 ( page not found)
2 tips for you:
1) Use Firefox + Firebug addon so you can debug javascript. You can tell it to stop script execution in a specified line to read each variable content at that moment.
2) Stop writting javascript code "by hand". Don't use ajax like that. Instead use a lightweight javascript libary such as jQuery (this one is very hot), dojo, mootools, prototype, etc..
Have fun!