SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2007
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    xHttpRequest() gives erroneous failure for file://

    I'm testing a web site in a local directory by opening index.html from the File/Open File... menu of Firefox. When I use xHttpRequest.send() to retrieve a file to include in my page, the callback's status argument is 8 and req.status is 0. I suppose that the 8 is correct in that the req.status isn't 200 but it seems that for file:// (as opposed to http://) that req.status == 0 might be treated as success. I haven't tested far enough yet to know what req.status would be if the file I tried to retrieve was missing.

  2. #2
    SitePoint Wizard
    Join Date
    Oct 2005
    Posts
    1,863
    Mentioned
    5 Post(s)
    Tagged
    2 Thread(s)
    Your hard drive is not a server and is not going to return a server code.

    Also, you may have an additional issue: javascript doesn't have access to your file system.

    Your best bet would be to set up an Apache development server on your machine.

  3. #3
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    xml HTTP Request

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yup when you load from local filesystem status=0 is success, and I think 2 is failure.

  5. #5
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm testing a web site in a local directory by opening index.html from the File/Open File... menu of Firefox. When I use xHttpRequest.send() to retrieve a file to include in my page,
    Put the page you are trying to retrieve using an xhr "on your server", i.e. in the server's folder. For apache, that will be something like Apache Group/Apace2/htdocs. You also need to put your .htm page with the js on it in that folder as well. Then start your server, and type this in your browser's address bar:

    http://localhost/myPage.htm

    Depending on what port you set up apache to listen on, you may have to do something like this:

    http://localhost:8080/myPage.htm

    You can also create folders within Apache's htdocs directory to organize your code, e.g:

    htdocs/assignment1/myPage.htm

    and then if you want to load that page, you would type the following into your browser's address bar:

    http://localhost/assignments/myPage.htm


Bookmarks

Posting Permissions

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