1

I am having trouble loading jquery with require.js

Here is the html script:

<script data-main="js/mainU.js" src="js/libs/require.min.js"></script>

Here is the mainU.js file

requirejs.config({
    enforceDefine: true,
    baseUrl: "libs",
    paths: {
        jquery: ["//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js",
         "jquery.min"],
        underscore: "underscore-amd.min",
        backbone: "backbone-amd.min"
    },

});

define(["jquery", "underscore", "backbone"],
    function ($, _, Backbone) {
        console.log("Test output");
        console.log("$: " + typeof $);
        console.log("_: " + typeof _);
        console.log("Backbone: " + typeof Backbone);
    }
);

The files are in the correct folders

2

2 Answers 2

1

I happened to not need the baseUrl, taking it away and just adding libs/ infront of the js files worked out.

So it looks like this now...

requirejs.config({
    enforceDefine: true,
    //baseUrl: "js",
    paths: {
        "jquery": ["http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min",
         "libs/jquery.min"],
        "underscore": "libs/underscore-amd.min",
        "backbone": "libs/backbone-amd.min"
    }

});

define(["jquery", "underscore", "backbone"],
    function ($, _, Backbone) {
        console.log("Test output");
        console.log("$: " + typeof $);
        console.log("_: " + typeof _);
        console.log("Backbone: " + typeof Backbone);
    }
);
Sign up to request clarification or add additional context in comments.

Comments

0

The error is because you are loading the jQuery from CDN , in which you are giving .js extension , remove the .js extension, it will work fine.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.