views:

1025

answers:

4

I've downloaded the examples for both the Request and Request.HTML and cannot make either work. I unzipped them to a folder and browsed to their index.html to execute them as is, but the response is always "The request failed." with no clues as to why.

I've played around with them with different permutations and can get the request to complete but it always fails. Is there any way to get a reason for failure? I've tried three different browsers turned off my firewall, used relative and absolute file references but nothing works. Am I missing something glarringly obvious? I'd post the code, but it is the examples exactly as is...

Any help would be awesome.

Cheers,

Justin.

+1  A: 

If I'm remembering correctly, AJAX requests in most browsers cannot be done via the local file system - you'll need an actual web server like Apache going. In Windows, XAMPP will get you up and running with Apache in minutes.

ceejayoz
You are rigth, AJAX need a web server that process the request (and in the same domain of the pages originating the response)
Eineki
A: 

Brilliant!! Thanks very much! I uploaded it to my nearest webserver and sure enough it works.

I did try doing some Ajax calls directly from my filesystem without any javascript libraries - using XMLHttpRequest() - and it worked fine, so this does seem like a strange limitation. Can I be sure this will always work from any webserver, however basic? It's just that this project I'm working on is going to be using multiple hosting environments, mainly just plain HTML type sites for the client enviornments of which I'll have no control... Is there a minimum specification?

Cheers ;)

+1  A: 

Most any webserver should work. It's just that your filesystem doesn't "respond" to browser requests the way a web server does:

ajax requests that are executed locally (against the file system) don't work well because the ajax logic is looking for a state change and a server response, neither of which are provided by your file system

-- http://forum.mootools.net/viewtopic.php?id=5009

The XMLHttpRequest object can handle more than just HTTP requests supposedly, but at least in mootools, it's not meant to. And "file:///..." is not an HTTP request. It's just taking a file from your file system and displaying it in the browser.

So the good news is: any web browser, including even a bare-bones one running on your local machine, should work fine :)

mltsy
A: 

The XMLHttpRequest() succeeds cause there's nothing wrong with making the local call. it's just different and the problem is in the buggy mootools isSuccess function. You gotta override it the Request options. Here's how jquery does it

    // Determines if an XMLHttpRequest was successful or not
httpSuccess: function( xhr ) {
    try {
        // IE error sometimes returns 1223 when it should be 204 so treat it as success, see #1450
        return !xhr.status && location.protocol === "file:" ||
            // Opera returns 0 when status is 304
            ( xhr.status >= 200 && xhr.status < 300 ) ||
            xhr.status === 304 || xhr.status === 1223 || xhr.status === 0;
    } catch(e) {}

    return false;
},
Daniel Linkov