-1

I find this answer to my problem How to include js file in another js file? but when run my application the resource not be found... I try to use

    var x = document.createElement('script');
    x.src = '../apps/appChangePwd/initApp.js';
    document.getElementsByTagName("head")[0].appendChild(x); 

and

 $.getScript('../apps/appChangePwd/initApp.js', function()
            {
                alert("okkk!!!");
            });

in the first case

returns   http://localhost:8080/apps/appChangePwd/initApp.js 404 (Not Found)

in the second

http://localhost:8080/apps/appChangePwd/initApp.js?_=1404291135662 404 (Not Found)

but my js file is in the correct path: apps/appChangePwd/ !!!

Community
  • 1
  • 1
padibro
  • 1,324
  • 10
  • 56
  • 95
  • http://stackoverflow.com/questions/950087/how-to-include-a-javascript-file-in-another-javascript-file – StrawHara Jul 02 '14 at 08:56
  • If you manually go to http://localhost:8080/apps/appChangePwd/initApp.js it does not return a 404? Otherwise your path is just not correct. – tholu Jul 02 '14 at 08:57
  • is `apps` is your context root ? – Yagnesh Agola Jul 02 '14 at 09:02
  • i'm confused. The path `localhost:8080/apps/appChangePwd/initApp.js ` retourn 404... because the correct path is `http://localhost:8080/**ZWebapp2**/apps/appChangePwd/initApp.js` – padibro Jul 02 '14 at 09:04
  • $.getScript start at the root (localhost) or at the path were i launch it? I launch $.getScript in `ZWebapp2/view/App.view.js` and the target file is `ZWebapp2/apps/appChangePwd/initApp.js` – padibro Jul 02 '14 at 09:08
  • ok it work ` $.getScript('apps/appChangePwd/initApp.js', function() { alert("okkk!!!"); });` – padibro Jul 02 '14 at 09:12

1 Answers1

1

You can use JQuery:

$.getScript('My_Js_File.js',function(){
    alert('Javascript File Loaded');
});
131
  • 1,363
  • 1
  • 12
  • 32