Rashad Valliyengal
Rashad Valliyengal

Reputation: 3162

JavaScript Runtime error 'ko' is undefined

I am new to KnockOut js.When I tried a simple Hello World Example in Visual Studio 2012 ,I am getting an runtime exception saying "Javascript Run time error:ko is undefined".Please help me

this is my code

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>App1</title>

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

    <!-- App1 references -->
    <link href="/css/default.css" rel="stylesheet" />
    <script src="/js/default.js"></script>
    <script src="/js/knockout-3.0.0.js" type="text/javascript"></script>
    <script src="/js/jquery.min.js" type="text/javascript"></script>


</head>
<body>
    <p>Hello, <span data-bind="text:name"></span>!</p>
    <script>
        ko.applyBindings({name:ko.observable('World')});  
    </script>
</body>
</html>

Upvotes: 4

Views: 16713

Answers (2)

user3456909
user3456909

Reputation: 81

Make sure you are using the correct reference number in all your references e.g If you installed knockout 3.1.0 from nuget and still using 2.2.1 in references then it can cause this error. I fixed that error by making sure that all my references matches the version I installed.

Upvotes: 4

Damien
Damien

Reputation: 8987

The error should become from the included javascript. May be they aren't available on the server. The follow snippet works.

<html>
<head>
    <meta charset="utf-8" />
    <title>App1</title>
    <script src="http://knockoutjs.com/downloads/knockout-3.0.0.debug.js" type="text/javascript"></script>
</head>
<body>
    <p>Hello, <span data-bind="text:name"></span>!</p>
    <script>
        ko.applyBindings({name:ko.observable('World')});  
    </script>
</body>
</html>

Upvotes: 2

Related Questions