Hari V
Hari V

Reputation: 31

jquery is not loaded when used with require.js

I am using the following code Html to load the scripts that I need. I am getting $ as Undefined. It is not able to load the jquery.

How can I get this to work.

<html>
<head>
<title>Using The Text Plugin With RequireJS</title>
<script  data-main="Scripts/init type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.6/require.min.js"></script>
<script type="text/javascript" language="javascript">

    require(['jquery', 'knockout-2.2.1', 'Template', 'text!Template.htm'], function ($, ko, t, temp) {

        $("body").append(temp);
        //make this new template engine our default engine
        ko.setTemplateEngine(t.myExternalTemplateEngine(t.templates));

        ko.applyBindings(t);

    });
</script>
</head>

code in Init.js in a separate file

require.config({
baseUrl:'Scripts',
paths: {

    'jquery': '//cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.js',
    'knockout-2.2.1': '//cdnjs.cloudflare.com/ajax/libs/knockout/2.2.1/knockout-min.js',
    'knockout.mapping-latest': '//cdnjs.cloudflare.com/ajax/libs/knockout.mapping/2.3.5/knockout.mapping.js',
    'Template': 'Template',
    'text': '//cdnjs.cloudflare.com/ajax/libs/require-text/2.0.5/text',
    'domready': '//cdnjs.cloudflare.com/ajax/libs/require-domReady/2.0.1/domReady.js'
   }

});

Upvotes: 1

Views: 335

Answers (1)

Simon Smith
Simon Smith

Reputation: 8044

Remove the .js from your paths configuration:

paths: {
    'jquery': '//cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery'
}

More detail in this example repo

Upvotes: 2

Related Questions