Javascript 如何在另一个js中包含js文件?

Javascript 如何在另一个js中包含js文件?,javascript,jquery,Javascript,Jquery,我找到了这个问题的答案,但是当运行我的应用程序时,找不到资源。。。 我试着用 var x = document.createElement('script'); x.src = '../apps/appChangePwd/initApp.js'; document.getElementsByTagName("head")[0].appendChild(x); 及 在第一种情况下 returns http://localhost:8080/apps/appChang

我找到了这个问题的答案,但是当运行我的应用程序时,找不到资源。。。 我试着用

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

在第一种情况下

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

http://localhost:8080/apps/appChangePwd/initApp.js?_=1404291135662 404 (Not Found)
但是我的js文件的路径是正确的:
apps/appChangePwd/

您可以使用JQuery:

$.getScript('My_Js_File.js',function(){
    alert('Javascript File Loaded');
});

如果您手动转到,它不会返回404吗?否则,您的路径就是不正确。是
应用程序
是您的上下文根吗?我很困惑。路径
localhost:8080/apps/appChangePwd/initApp.js
retourn 404。。。因为正确的路径是
http://localhost:8080/**ZWebapp2**/apps/appChangePwd/initApp.js
$。getScript从根目录(localhost)或启动它的路径开始?我在
ZWebapp2/view/App.view.js
中启动了$.getScript,目标文件是
ZWebapp2/apps/appChangePwd/initApp.js
$.getScript('My_Js_File.js',function(){
    alert('Javascript File Loaded');
});