11

I have two identical html files (except for EOL character - one is LF and the other is CRLF), which I use to load 2 audio files using XMLHttpRequest. I don't use any web server (because the purpose is to load it in ipad and run it without any web server) - I just use open those with Safari (for Mac).

The mind-boggling thing is, the file with LF endlines is able to load the audio files just fine, but the one with CRLF got:

Cross origin requests error (XMLHttpRequest cannot load file:///directories_to_files/cheer_and_clap.mp3. Cross origin requests are only supported for HTTP.)

You can have a look at the files. I haven't tested on Safari for Windows version yet.

p.loadBuffer = function(url, index) {
    var request = new XMLHttpRequest();
    console.log(url);
    request.open("GET", url, true);
    request.responseType = "arraybuffer";
        console.log(request);
    }
    request.onerror = function() {
        alert('BufferLoader: XHR error');
    }
    request.send();
}

Any explanation for why this is happening?

David Cain
  • 16,484
  • 14
  • 65
  • 75
  • I don't get the same error as you I'm afraid - for both files I get `INVALID_STATE_ERR: DOM Exception 11: An attempt was made to use an object that is not, or is no longer, usable.` `console.log(request);` does get echoed to the console log tho. – Pebbl Oct 25 '12 at 16:07
  • 2
    both won't work, as local files are indeed, not allowed for XHR. there must be something else. – Eliran Malka Oct 25 '12 at 16:11
  • Thanks guys. That's really strange.. I tried everything (including clearing the cache, restart the comp, etc.), it still happen on my computer, but testing on another computer both of them don't work as it supposed to be so. – Pham Tuan Minh Oct 25 '12 at 17:18
  • 2
    I think it's the byte order mark, the CRLF file has it at the beginning while the LF file doesn't have it. Try to remove it, for instance use the command `dd if=CRLFEOL.html of=CRLFEOL2.html bs=1 skip=3` – cristis Oct 25 '12 at 18:07
  • they both should have been denied because usually xmlHttp requests are not allowed cross domains. this is for security reasons. – alfred Oct 30 '12 at 11:16
  • What version of safari are you using? I tried both files in Safari Version 6.0 (8536.25). Both work for me. However, when I loaded the same files in Google Chrome, they give the XHR error. – justspamjustin Oct 30 '12 at 21:22

0 Answers0