RequireJS baseURL问题

时间:2013-11-15 01:55:00

标签: javascript php jquery backbone.js requirejs

如果我在我的domain.com/seeker/job页面加载

<script type="text/javascript" src="{{ asset('assets/backbone/js/libs/require/require.js')}}"></script>
<script type="text/javascript" src="{{ asset('assets/backbone/main.js')}}"></script>

main.js文件

 require.config({
 baseUrl: "/",
       paths:{
           "jquery": "domain.com/js/libs/jquery/src/jquery",
           "underscore": "domain.com/js/libs/underscore/underscore",
           "backbone": "domain.com/js/libs/backbone/backbone"
       },
        waitSeconds: 7
    });

   require(['assets/backbone/app'], function(AppView){
    new AppView;
});

错误

GET http://domain.com/manipulation/_evalUrl.js 500 (Internal Server Error) require.js:1881
Uncaught Error: Script error for: manipulation/_evalUrl
http://requirejs.org/docs/errors.html#scripterror require.js:163
GET http://domain.com/ajax.js 500 (Internal Server Error) require.js:1881
Uncaught Error: Script error for: ajax
http://requirejs.org/docs/errors.html#scripterror require.js:163
GET http://domain.com/serialize.js 500 (Internal Server Error) require.js:1881
Uncaught Error: Script error for: serialize
http://requirejs.org/docs/errors.html#scripterror require.js:163
GET http://domain.com/ajax/jsonp.js 500 (Internal Server Error) require.js:1881
Uncaught Error: Script error for: ajax/jsonp
http://requirejs.org/docs/errors.html#scripterror require.js:163
GET http://domain.com/ajax/xhr.js 500 (Internal Server Error) require.js:1881
Uncaught Error: Script error for: ajax/xhr
http://requirejs.org/docs/errors.html#scripterror require.js:163
GET http://domain.com/ajax/script.js 500 (Internal Server Error) require.js:1881
Uncaught Error: Script error for: ajax/script
http://requirejs.org/docs/errors.html#scripterror require.js:163
GET http://domain.com/ajax/load.js 500 (Internal Server Error) require.js:1881
Uncaught Error: Script error for: ajax/load
http://requirejs.org/docs/errors.html#scripterror require.js:163
GET http://domain.com/effects.js 500 (Internal Server Error) require.js:1881
Uncaught Error: Script error for: effects
http://requirejs.org/docs/errors.html#scripterror require.js:163
GET http://domain.com/effects/animatedSelector.js 500 (Internal Server Error) require.js:1881
Uncaught Error: Script error for: effects/animatedSelector
http://requirejs.org/docs/errors.html#scripterror require.js:163
GET http://domain.com/dimensions.js 500 (Internal Server Error) require.js:1881
Uncaught Error: Script error for: dimensions
http://requirejs.org/docs/errors.html#scripterror require.js:163
GET http://domain.com/exports/amd.js 500 (Internal Server Error) require.js:1881
Uncaught Error: Script error for: exports/amd
http://requirejs.org/docs/errors.html#scripterror require.js:163
GET http://domain.com/deprecated.js 500 (Internal Server Error) require.js:1881
Uncaught Error: Script error for: deprecated
http://requirejs.org/docs/errors.html#scripterror require.js:163
GET http://domain.com/offset.js 500 (Internal Server Error) require.js:1881
Uncaught Error: Script error for: offset
http://requirejs.org/docs/errors.html#scripterror require.js:163
Uncaught Error: Load timeout for modules: 
http://requirejs.org/docs/errors.html#timeout 

错误列表很长,它的作用就好像它找不到URL并且它正在加载基本网址?我做错了什么?

2 个答案:

答案 0 :(得分:1)

如果您尝试将/templates作为网址的第一部分,请尝试设置baseUrl。默认情况下,./会解析为/seeker目录。

require.config({
    baseUrl: "/",
    paths:{
        "jquery": "js/libs/jquery/src/jquery",
        "underscore": "js/libs/underscore/underscore",
        "backbone": "js/libs/backbone/backbone"
    },
    waitSeconds: 7
});

答案 1 :(得分:0)

看了这一年的帖子,我也有同样的问题。

您尝试提取的jquery文件不是来自&#34; src&#34;文件夹,但&#34; dist&#34;。

因此,在main.js文件中,将一行更改为

"jquery": "domain.com/js/libs/jquery/dist/jquery"