locked
jQuery Date Undefined

    Question

  • Has anyone else encountered a problem with referencing jQuery 1.6.* where it says that Date() is undefined? I don't remember seeing this on earlier projects, but now it reliably repros on an app created from one of the built-in templates & unmodified except for the addition of

    <script src="/js/jquery-1.6.4.js"></script>
    

    to default.html and landingPage.html (or splitPage.html). I don't think I've done anything really foolish - I was one of the interns working on apps this summer, but my project was all in XAML and C# so I never had to write a Metro style app in JavaScript.

    Thursday, September 29, 2011 4:51 PM

Answers

  • I downloaded the latest and added it to my project in the js folder.  I then added this to the default.htm just before the closing head tag:


    <script src="/js/jquery-1.6.4.js"></script>


    and this to splitpage.html and categoryPage.html just before the closing head tag:

    <script type="ms-deferred/javascript" src="/js/jquery-1.6.4.js"></script>

    It all works great!


    Is this the same thing you did?


    -Jeff


    Jeff Sanders (MSFT)
    • Marked as answer by Ted.D Thursday, September 29, 2011 6:12 PM
    Thursday, September 29, 2011 5:46 PM
    Moderator

All replies

  • I downloaded the latest and added it to my project in the js folder.  I then added this to the default.htm just before the closing head tag:


    <script src="/js/jquery-1.6.4.js"></script>


    and this to splitpage.html and categoryPage.html just before the closing head tag:

    <script type="ms-deferred/javascript" src="/js/jquery-1.6.4.js"></script>

    It all works great!


    Is this the same thing you did?


    -Jeff


    Jeff Sanders (MSFT)
    • Marked as answer by Ted.D Thursday, September 29, 2011 6:12 PM
    Thursday, September 29, 2011 5:46 PM
    Moderator
  • I downloaded the latest and added it to my project in the js folder.  I then added this to the default.htm just before the closing head tag:


    <script src="/js/jquery-1.6.4.js"></script>


    and this to splitpage.html and categoryPage.html just before the closing head tag:

    <script type="ms-deferred/javascript" src="/js/jquery-1.6.4.js"></script>

    It all works great!


    Is this the same thing you did?


    -Jeff


    Jeff Sanders (MSFT)

    Almost the same - I missed the type="ms-deferred/javascript" attribute on the one in splitPage.html. Now it appears to be working as expected. Is there documentation on what that attribute means / when it should be used?
    Thursday, September 29, 2011 6:12 PM
  • Since we are in preview still I do not think all of the documentation has been finished.  Basically what this does is allow the script to be loaded after all other scripts have been loaded and then will only load functions if they have not already been loaded into the namespace.  You will notice this pattern on all of the included .js files in those fragment pages.

    So... as a rule, if you include a .js file in pages other than default.html, make sure you use the type="ms-deferred/javascript" attribute to include it!

    Jeff


    Jeff Sanders (MSFT)
    Thursday, September 29, 2011 6:19 PM
    Moderator
  • I have a similar problem with jquery. I am writing my app to run on Metro and browsers. I have an iframe that runs my app.

    If I use  <script src="/Scripts/jquery-1.6.1.min.js" type="text/javascript">, VS11 Express says that some variable is undefined. But if I use ms-deferred VS11 does not complain, but I get an error because I have to use ms-deferred on all of my scripts.

    I have a form that submits text back to my server like this:

    <script type="ms-deferred/javascript">

    function HandleSubmit() {
        if (WebAcre_Browser == "IE" && WebAcre_BrowserVersion == "8.0")
            $("#ChatForm").submit(WebAcre_Post);
        return false;
    }

    </script>

    <form id="ChatForm" action="" onsubmit="HandleSubmit();">

    Now I get a run time error VS11 says it cannot find HandleSubmit(). Anyone seen this?

    Thanks,

    • Edited by Mario Rosario Friday, December 16, 2011 5:46 AM fix formatting problem
    Friday, December 16, 2011 5:44 AM
  • Hi Mario,

    If I understand the structure of your app, you are including the script inline in the page.  You should use the same pattern as the templates do and separate your code from your html, then include your .js file as specified above.

    -Jeff


    Jeff Sanders (MSFT)
    Friday, December 16, 2011 2:10 PM
    Moderator
  • Hi Jeff,

    Good suggestion. Let me try that. I do it in line for debug purpose. Once I know the feature is working I move it to the templates. Sometimes I don't know if the template is the cached version and it confuses me especially when debugging.

    JQyery has a weired behavior on IE 8, which I am not able to fix yet but I would still like to support it because I still have 3 XP machines, 2 Vista machines, 2 Windows 7 and one Window 8 preview. Not to mention I have 3 windows servers phew ... lol. I don't know what I am doing with all these machines.

    More on the fix later, good suggestion.

    Best,
    Mario

    PS: They are all legal licenses.
    • Edited by Mario Rosario Saturday, December 17, 2011 12:19 AM Qualify myself
    Saturday, December 17, 2011 12:07 AM
  • My experience has been that if I add "ms-deferred/javascript" then it simply ignores the JavaScript file .... which is not what I want.
    Thursday, December 13, 2012 3:48 PM