CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2006
    Posts
    230

    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
    Last edited by umen; February 7th, 2009 at 01:51 PM.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    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.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Aug 2002
    Location
    Brazil
    Posts
    730

    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!
    All consequences are eternal in some way.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured