JQuery getScript not working in Android WebView when using local resources / HTML / resources

I have my own Android application that contains a WebView. All my HTML, js and css are added to the Android project in the resource folder, so I initialize my WebView in Java code, for example ...

WebView webView = (WebView)findViewById(R.id.webview);
webView.loadUrl("file:///android_asset/index.htm");

Everything works fine until I need to load an additional js file dynamically from JavaScript using the jQuery getScript method ...

var scriptUrl = "scripts/dynamicScript.js";
$.getScript(scriptUrl , function() { alert("Success"); })
    .fail(function(e){ alert("failed: " + JSON.stringify(e)); });

Basically, the script does not load, and I get the following message:

failed: {"readState":4,"responseText":"", "status":404, "statusText":"error"}

I also tried the following alternatives for scriptUrl and got exactly the same result and message:

"/scripts/dynamicScript.js"
"./scripts/dynamicScript.js"
"android_asset/scripts/dynamicScript.js"
"../android_asset/scripts/dynamicScript.js"
"file:///android_asset/scripts/dynamicScript.js"

I expect this to have something to do with politics of the same origin . Any help in getting this work appreciated.

EDIT:

$.getScript().

'script' ajax. , ...

$.ajax({
   url: scriptUrl, 
   dataType: 'script', 
   success: function() { alert("Success"); },
   error: function(e){ alert("failed: " + JSON.stringify(e)); },
   async: true
});

script . , , (, dynamicScript.js, )...

$("<script type='text/javascript' src='" + scriptUrl +"'></script>").appendTo("head");

, , , , solutiojn IE, , ...

WebView webView = (WebView)findViewById(R.id.webview);
webView.loadUrl("http://remote-server/index.htm");
+5
1

, , , , ...

var scriptUrl = "scripts/dynamicScript.js";
var head = document.getElementsByTagName("head")[0];
script = document.createElement('script');
script.type = 'text/javascript';
script.src = scriptUrl;
script.onload = function() { alert("Success"); };
script.onerror = function(e) { alert("failed: " + JSON.stringify(e)); };
head.appendChild(script);

. , jQuery script .

+6

All Articles