package;
import haxe.Http;
class Application implements IApplication {
public function new() {
testFileAccess(); }
private function testFileAccess() {
var url : String = "data/_setup.xml";
var http : Http = new Http( "" ); http.url = url;
http.onData = onHTTPData; http.onError = onError; http.onStatus = onStatus;
http.request(false); }
private function onHTTPData( data : String ) {
trace( "onHTTPData:" + data ); }
private function onError( msg : String ) { trace( "onError:" + msg ); }
private dynamic function onStatus( status : Int ) { trace( "onStatus:" + status ); }}
nekotools server -d path_to_directory
this has nothing to do with the Chrome security restriction.
// If the request is local and we have data: assume a success// (success with no data won't get notified, that's the best we// can do given current implementations)if ( !status && s.isLocal && !s.crossDomain ) { status = responses.text ? 200 : 404;}
haxe.Http.prototype = {
request: function(post) {
var onreadystatechange = function() {
... switch(s) {
default:
if (s == 0 && r.responseText ) { me.onData(r.responseText); } else { me.onError("Http Error #" + r.status); }}
@Tero Tolonen: No, this has nothing to do with the Chrome security restriction. I'm already running it with local file access. And I have the same problem with Firefox! It runs fine when using jQuery.ajax().
Should I file a feature request or just implement a solution and commit?
haxe.Http.prototype = {... ,request: function(post) { var me = this; var r = new js.XMLHttpRequest(); var onreadystatechange = function() { if(r.readyState != 4) return; var s = (function($this) { var $r; try { $r = r.status; } catch( e ) { $r = null; }
// local protocol fix borrowed from jQuery:
// If the request is local and we have data: assume a success
// (success with no data won't get notified, that's the best we // can do given current implementations)
if (!$r) { $r = (function($r) { try { var ajaxLocation = location.href; } catch( e ) { ajaxLocation = document.createElement( "a" ); ajaxLocation.href = ""; ajaxLocation = ajaxLocation.href; } var rurl = /^([\w.+-]+:)(?:\/\/([^\/?#:]*)(?::(\d+)|)|)/, rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/, ajaxLocParts = rurl.exec( ajaxLocation.toLowerCase() ) || [], isLocal = rlocalProtocol.test( ajaxLocParts[ 1 ] ); if (isLocal) { $r = r.responseText ? 200 : 404; } return $r; })($r); }
return $r; }(this));