Answered jQuery?

  • Thursday, September 15, 2011 11:35 PM
     
     

    How do I use jQuery with Windows 8?

    When I run my program that has the jquery.min.js file included, I get no errors, but my page does nothing...

     

All Replies

  • Friday, September 16, 2011 12:27 AM
     
     
    I've used jQuery in the past with JS/HTML5 on Windows 8 in the past with some success. Could you provide more details? Perhaps narrow it down to a very simple page that "does nothing" ?
  • Friday, September 16, 2011 3:21 AM
     
     
    Remember that you can't use external link. The best way to get it to work is to download the jquery file to your local project directory. I got it to work perfectly fine this way.
  • Friday, September 16, 2011 3:34 AM
     
      Has Code

    As you can see, my code appears to be fine:

     

    <!DOCTYPE html>
    
    <html>
    
    <head>
    
        <meta charset="utf-8" />
    
        <title>WinWebApp2</title>
    
        <!-- WinJS references -->
    
        <link rel="stylesheet" href="/winjs/css/ui-dark.css" />
    
        <script src="/winjs/js/base.js"></script>
    
        <script src="/winjs/js/wwaapp.js"></script>
    
        <!-- WinWebApp2 references -->
    
        <link rel="stylesheet" href="/css/default.css" />
    
        <script src="/js/default.js"></script>
    
        <script src="/js/jquery.min.js"></script>
    
    </head>
    
    <body>
    
        <span id="asdf"></span>
    
    </body>
    
    </html>

     

    (function () {
        'use strict';
        // Uncomment the following line to enable first chance exceptions.
        // Debug.enableFirstChanceException(true);
    
        WinJS.Application.onmainwindowactivated = function (e) {
            if (e.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
                $(document).ready(function () {
                    $("#asdf").html("asdf");
                })
            }
        }
    
        WinJS.Application.start();
    })();

    I throw no errors, but after the "clock" splash screen, my cursor shows that something is loading and then it just shows a blank screen.
    Thanks

  • Friday, September 16, 2011 3:41 AM
     
     

    Your code should execute just fine. Have you tried setting a breakpoint on the jQuery call and stepped through it to see it's working?


    Microsoft MVP - Bing Maps
    Blog: http://pietschsoft.com | Web.Maps.VE - ASP.NET AJAX Bing Maps Server Control
  • Friday, September 16, 2011 3:57 AM
     
     
    Nope, but I don't see where I would put one that would make a difference..
  • Friday, September 16, 2011 10:03 PM
     
     
    Do you get any messages in the JavaScript Console?  Make sure you have warnings, errors and information all enabled.
  • Saturday, September 17, 2011 12:39 AM
     
     

    Uncomment this line of code: // Debug.enableFirstChanceException(true);

    Do you still see no errors?

    Also, what version of jQuery are you using?

    Also make sure that you have included the jquery.min.js file in your project. I've just created a project with jquery 1.6.4 and had no issues with it working.

    • Edited by David Owens Saturday, September 17, 2011 12:47 AM
    •  
  • Sunday, September 18, 2011 5:13 PM
     
     

    Are any other Metro UI apps loading? This sounds like something that happened to me where all the metro ui apps except control panel and internet explorer would stop loading after the splash screen.

     

    I never did find a way to fix it other than a re-install.

  • Tuesday, September 20, 2011 6:49 AM
     
     
    Did you get this resolved?
    Microsoft MVP - Bing Maps
    Blog: http://pietschsoft.com | Web.Maps.VE - ASP.NET AJAX Bing Maps Server Control
  • Thursday, September 22, 2011 7:13 PM
     
     
    I'm trying to use version 1.6.4, it worked, but I can not use the variable jQuery.getJSON. Windows does not seem to receive the data. : /
    Does anyone have a solution?
  • Friday, September 23, 2011 8:38 PM
     
     Answered Has Code

    So jQuery is a little too smart and realizes you are making a cross-domain request, but doesn't realize you are in a Windows 8 Metro style app and so rejects this request before it ever gets to XmlHttpRequest.

    A simple workaround is to tell jQuery that it should allow cross domain requests:

    jQuery.support.cors = true;
    $.getJSON('http://search.twitter.com/search.json?q=windows8', function (data) {
        console.log(data.results[0].text);
    });
    

    Cheers,

    -Jeff

    • Marked As Answer by maxhudson Saturday, September 24, 2011 4:35 AM
    •  
  • Saturday, September 24, 2011 7:33 PM
     
     

    When I try to run the jQuery displays the following error..


    JavaScript runtime error: 'Date' is undefined

    Anyone else having this problem?

  • Friday, September 30, 2011 3:43 PM
     
     

    For future readers of this thread, the "Date is undefined" problem came up in its own thread: http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/4c546297-035a-4777-af39-564d1db71a8c

    -JF