瀏覽代碼

Merge pull request #3353 from derRaab/development

Added jQuery approach to enabled local HTTP requests with JavaScript
Nicolas Cannasse 10 年之前
父節點
當前提交
018ad840bb
共有 1 個文件被更改,包括 9 次插入0 次删除
  1. 9 0
      std/haxe/Http.hx

+ 9 - 0
std/haxe/Http.hx

@@ -203,6 +203,15 @@ class Http {
 			if( r.readyState != 4 )
 				return;
 			var s = try r.status catch( e : Dynamic ) null;
+			if ( s != null ) {
+				// If the request is local and we have data: assume a success (jQuery approach):
+				var protocol = js.Browser.location.protocol.toLowerCase();
+				var rlocalProtocol = ~/^(?:about|app|app-storage|.+-extension|file|res|widget):$/;
+				var isLocal = rlocalProtocol.match( protocol );
+				if ( isLocal ) {
+					s = r.responseText != null ? 200 : 404;
+				}
+			}
 			if( s == untyped __js__("undefined") )
 				s = null;
 			if( s != null )