4

When I start my project and it loads up my page, I get the following error:

0x800a138f - JavaScript runtime error: The value of the property '$' is null or undefined, not a Function object.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestPage.aspx.cs" Inherits="WebsiteTest.TestPage" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Web Service Test</title>
    <script src="http://ajax.microsoft.com/ajax/jQuery/jquery-2.1.1.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $('#tbDetails').hide();
            $('#btnClick').click(function () {
                alert('test');
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <input type="button" id="btnClick" value="Get Data" />
        <table id="tbDetails">
            <thead style="background-color: #DC5807; color: White; font-weight: bold">
                <tr style="border: solid 1px #000000">
                   <td>Description</td>
                   <td>Comments</td>
                </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </form>
</body>
</html>

I'm assuming, it's got something to do with JQuery not being included even though it should be.

Any idea what the problem might be?

Thanks.

Update:

Works when using

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>

Will keep researching it as to why it won't work with the MS one! It is definitely there as I can download it!

Update

I figured out 2 problems:

  1. I was using https on my localhost and I should have used the https of jquery. Changing this got rid of my original error but it gave me some other error that I'm still researching.

  2. My code works perfectly (and more since I've open this thread) as now I'm also calling a REST web service and manipulating the data returned without a single error but this only works in Chrome and Firefox! What the hell is up with IE11

7
  • @celeriko the code is already wrapped in a ready handler!
    – Pointy
    May 21, 2014 at 14:20
  • @Pointy what do you mean?
    – Thierry
    May 21, 2014 at 15:05
  • He (celeriko) was talking about the $( ... ) wrapper around the code in your inline script block. $(function() { ... }) means exactly the same thing as what was suggested in the (now deleted) comment.
    – Pointy
    May 21, 2014 at 15:38
  • You can use the browser "Network" debug console to see whether the HTTP request to fetch jQuery is working. I don't see why it would not work; that URL is correct. I would try getting rid of the "type" attributes on all your <script> tags, but even those look fine here.
    – Pointy
    May 21, 2014 at 15:39
  • This is insane!! It just won't work! The minute I change the src to use google's one, it works! I'll keep researching it, but what a waste of time!
    – Thierry
    May 21, 2014 at 16:18

4 Answers 4

2

Drop the protocol from the src and the browser will then use whatever your page uses. Here is an example

<script src="//ajax.microsoft.com/ajax/jQuery/jquery-2.1.1.js" type="text/javascript"></script>
1

Add this meta tag in your head. I was having same problem and I solved it by this

<meta http-equiv="X-UA-Compatible" content="IE=edge;" />
0

Have you tried extracting whole js code into separate file and then using it on your website using ClientScriptManager.RegisterClientScriptBlock?

2
  • I haven't. I'm following a sample I found online and I've downloaded the project and it doesn't have any ClientScriptManager.RegisterClientScriptBlock used anywhere. I haven't tried running their project but it looks pretty straight forward! The strange thing is that I've got 2 other test projects and both of them are accepting JQuery no problem but they're on different machines. I'm still trying to spot what's different between the 2, but to no avail.
    – Thierry
    May 21, 2014 at 15:04
  • I've seen that it's not working on the browser level. Try forcing "edge" standards. That was the solution for me in many cases.
    – Darj
    May 22, 2014 at 8:03
0

I have't found the answer to this very annoying problem so I am adding my solution (which may not be the only one, but here goes).

If your physical folder path includes an underscore, it will fail to load jQuery. So, if you dropped your website to lets say C:\MyRoot\MyFolder_2\WebSite1\ then it won't work. However, if you remove the underscore and it becomes C:\MyRoot\MyFolder2\WebSite1\ it will work and jQuery will suddenly be loaded. jQuery loaded = no more errors.

Hope this helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.