Clem
Clem

Reputation: 11824

Windows store app - jQuery error

I'm trying to import jQuery into blank javascript app, but keep getting same error: JavaScript runtime error: 'jQuery' is undefined. I don know the reason for this.

My whole procedure:

  1. Create new Blank app project
  2. Add existing item jquery-1.8.2-win8-1.0 in js folder
  3. Drag and drop added item into default.html head
  4. Add some jquery code in default.js

and now, i'm getting this error: JavaScript runtime error: '$' is undefined. But if I delete added jQuery code(didn't notice before) it throw's me another error:JavaScript critical error at line 4, column 1 in ms-appx://8cce31f0-7793-41f7-875e-c41dd9ade2c7/js/jquery-1.8.2-win8-1.0.js.

I'm trying to get jquery to work for last several hours, but without success.

HTML code:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>jquery</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>

    <!-- jquery references -->
    <link href="/css/default.css" rel="stylesheet" />
    <script src="/js/default.js"></script>
    <script src="js/jquery-1.8.2-win8-1.0.js"></script>
</head>
<body>
    <p>Content goes here</p>
</body>
</html>

jQuery code:

$("*").on("click", function () { });

Error's:

1. error 2. error

Video: Error - jQuery

Upvotes: 1

Views: 968

Answers (3)

Sampson
Sampson

Reputation: 268344

First of all, thank you for the video - this would have been nearly impossible to solve without it.

I noticed your jQuery file was 2.0mb; this didn't look right. And then the error message took us into its contents to point out a syntax error, where we saw a slew of HTML tags — you appear to have downloaded from the GitHub viewer page, rather than from the source file itself. You should instead download the RAW file.

Please note also that this is an older version of jQuery, and not a fully-supported version. I am the primary developer behind the appendTo repo, and am excited to announce that jQuery 2.0 (pre-release builds available) should work really well on its own in a Windows Store App.

I wrote about this recently over on nettuts: Building Windows Store Applications With jQuery 2.0

Upvotes: 1

Ali Shah Ahmed
Ali Shah Ahmed

Reputation: 3333

Try rearranging the scripts you added. Include jQuery js file before your default.js file. Something like this:

<script src="js/jquery-1.8.2-win8-1.0.js"></script>
<script src="/js/default.js"></script>

Default.js tries to use jQuery which is not yet added. So rearranging might help.

Upvotes: 0

Eli
Eli

Reputation: 14827

Try to put:

<script src="js/jquery-1.8.2-win8-1.0.js"></script>

after:

<link href="//Microsoft.WinJS.1.0/css/ui-dark.css" rel="stylesheet" />

This error is probably because you're not include jQuery library before writting jQuery code and make sure the path to your file is correct

Upvotes: 0

Related Questions