Can't include other Javascript in default.js

May 11, 2015 at 6:45 AM
Edited May 11, 2015 at 6:52 AM
Hi, I find in WAT template, I can't include other JS File like JQuery

Maybe is my progress wrong, but I tried do same step in blank WinJS Universal App template was success.

Here is my including steps:
  1. Add JQuery.js to project "js" folder. Which content JQuery lib.
  2. Add <script src="/js/jquery.js"></script> in default.html
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>Site2App1</title>

    <!--
    *** WARNING ***
    This file is not used for the Web Application Template (WAT), the root html 
    file used is in /web/template/wat-wrapper.html and that file is referenced 
    as the "start page" in the package.appxmanifest

    Do not use this file if you are using the WAT! It is only here because most 
    documentation sources refer to it.
    -->

    <!-- WinJS references -->
    <link href="//Microsoft.WinJS.2.0/css/ui-dark.css" rel="stylesheet" />
    <script src="//Microsoft.WinJS.2.0/js/base.js"></script>
    <script src="//Microsoft.WinJS.2.0/js/ui.js"></script>

    <!-- Site2App1 references -->
    <link href="/css/default.css" rel="stylesheet" />
    <script src="/js/jquery.js"></script>
    <script src="/js/default.js"></script>

</head>
<body>
    <p>Content goes here</p>
</body>
</html>
  1. Add some using JQuery statement in default.js:
// For an introduction to the Blank template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232509
(function () {
    "use strict";

    var app = WinJS.Application;
    var activation = Windows.ApplicationModel.Activation;

    app.onactivated = function (args) {
        if (args.detail.kind === activation.ActivationKind.launch) {
            if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
                // TODO: This application has been newly launched. Initialize
                // your application here.
            } else {
                // TODO: This application has been reactivated from suspension.
                // Restore application state here.
            }

            getJson();
            //args.setPromise(WinJS.UI.processAll());
        }
    };


    ///////////////get json////////////////
    function getJson() {
        var JsonUrl = "https://www.googleapis.com/freebase/v1/text/en/bob_dylan"

        $.getJSON(JsonUrl, function (data) {
            alert("Data Loaded: " + data);
        });
    }

    app.start();

})();
  1. Run, and I will got error
    Image
Event I tried using simple self define function, there still have error when I calling function which content another JS file.

This sample project upload to here:
WAT Project (won't work)

Blank Project(Can Include and works)

Any suggestion?
May 11, 2015 at 8:09 AM
Ok... fast find solution by self after posting this question :P...

It should include in /template/wat-wrapper.html
not /default.html

Marked as answer by thkaw on 5/11/2015 at 1:20 AM