C# ASP.NET SQL SERVER

Microsoft JScript runtime error object expected with jQuery

I was trying to get a simple piece of jQuery to work and was running up against this error in Internet Explorer (IE):

Microsoft JScript runtime error: object expected

The problem turned out to be that I wasn't referencing jQuery to the correct path. The trick I discovered, if you're using Visual Studio, is to just drag the JavaScript file from the Solution Explorer into the <head> element on your page and it will insert the correct reference for you.

UPDATE (9 July 2009):

I am referencing jQuery from the Google CDN now:

<script src="http://www.google.com/jsapi"></script>
    <script>
        google.load("jquery", "1.3.2");
        google.load("jqueryui", "1.7.2");
</script>

Using this technique will also get rid of this error and improve performance.

The first reference to jQuery (1.3.2) is for the core jQuery library. The second reference to (1.7.2) is for the optional jQuery UI library that you will only need if you are using the UI components/elements of the jQuery library. If you are using jQuery to manipulate the DOM only then you won't need the UI reference.

 

» Similar Posts

  1. AZGroups Forward/Back Button History and jQuery
  2. ASP.NET MVC with jQuery DynaTree plugin for Checkboxes
  3. Changing Graffiti to use Google Analytics Async

» Trackbacks & Pingbacks

    No trackbacks yet.
Trackback link for this post:
http://guyellisrocks.com/trackback.ashx?id=121

» Comments

  1. amjad khan avatar

    make sure the script tag in the head tag that references jquery ends with '</script>' and not '/>'. the same as dragging the script file onto your markup

    THX

    amjad khan — July 9, 2009 11:15 AM
  2. Howie M avatar

    Search the problem , your page came up.

    Worked for me ... thank you.

    Howie M — August 8, 2009 10:46 AM
  3. Intekhab avatar

    Thanks Amjad and Ellis, found you after breaking my head for nearly 10 hours on this error and your solution worked. You guys rock!!!!!

    Intekhab — October 20, 2009 11:22 AM
  4. Ranjit Kumar avatar

    Amjed, half a day of my precious life already had gone down the drain trying to get Jquery to work in a dummy Asp.net web app. Your information saved further time being lost, much appreciate it.

    Ellis, thanks for sharing info on using declarative syntax to refer to a particular version of jquery.

    Ranjit Kumar — October 23, 2009 1:56 PM
  5. Pradeep avatar

    Good Information, saved my time.

    Thanks Amjed and ellis.

    Pradeep — December 28, 2009 5:36 AM
  6. Joe avatar

    Worked for me! Thanks very much

    Joe — January 25, 2010 12:13 PM
  7. Pat avatar

    I spent so much time trying to 'debug' this and with a simple drag and drop, my link now works!

    Pat — March 30, 2010 4:17 PM
  8. Don S avatar

    You hit the error eactly. It hlped me a lot. thanks

    Don S — June 13, 2010 10:52 PM
  9. Victor X avatar

    Just can not THANK you enough.

    This stupid error drove me crazy for days.

    Victor X — August 11, 2010 3:44 AM
  10. powerloop avatar

    Thanks a million .... ! I could help my friend solve this issue which has been consuming him for days :)

    powerloop — August 24, 2010 10:46 AM
  11. Alberto avatar

    Thanks a lot ... I have spent so much time before I found your usefull page!!!!!

    Alberto — October 24, 2010 2:46 PM
  12. Ali  avatar

    I am having the same issues using Internet Explorer 8. FireFox has no issues. Any project i use for Jquery or silver light has issues

    I downloaded open source projects from http://jqmvcgrid.codeplex.com/ . Give the same error "Microsoft JScript runtime error: '$.jgrid' is null or not an object"

    Another application from blog.maartenballiauw.be/.../CarTrackr-Sampl gives the same error.

    Any advice would be helpful

    Ali — October 27, 2010 10:09 AM
  13. Saami avatar

    I have this problem in ie 6 but when I copy the .js files to local machine and refer it in the script tag it works fine.

    I am trying to make use of ajax.aspnetcdn.com/.../jquery-1.4.4.js through my visual studio editor and facing this problem.

    As per your guidance if I am referencing "http://www.google.com/jsapi" then from where should I drag this?. if its a local file then I can drag it from the solution explorer but if am referencing google or aspnetcdn then how do I drag that URL?

    Please help.

    Saami — December 7, 2010 9:33 AM
  14. guy ellis avatar

    @Saami - If you're trying to get intellisense in Visual Studio then you need a local copy of the jquery-1.4.1-vsdoc.js file and you would drag that onto your view.

    If you're just trying to use jQuery in a production style environment then you would copy the above code into your .master file or view.

    guy ellis — December 7, 2010 11:04 AM
  15. Ved avatar

    perfect...thank you very much. Drag n drop did not work for me but adding links from google did.

    Ved — January 5, 2011 12:24 PM
  16. sandeep avatar

    Thanks a lot, after dragging the jquery its works fine

    sandeep — February 19, 2011 9:30 AM
  17. Paul S avatar

    Of course, on my development machine had high security settings so jquery would not work!

    Reset IE security settings a bit lower and it worked!

    A good tip if your developing on server 2008 which has high security within IE by default.

    Paul S — April 20, 2011 7:33 AM
  18. Peter avatar

    Thank you for this article. I just want to notice that make sure you don't forget to include you jquery.min file, because I forgot and it did not work.

    So final solution:

    <script type="text/javascript" src="http://www.google.com/jsapi"></script>

    <script type="text/javascript">

    google.load("jquery", "1.3.2");

    google.load("jqueryui", "1.7.2");

    </script>

    <script type="text/javascript" src="path/to/your/jquery/file/jquery.min.js"></script>

    Peter — January 23, 2012 4:26 AM
  19. Jeff avatar

    Thanks, it worked. I later found that if you don't want to reference an outside link, you can try adding

    <configuration>

    <system.web>

    <authorization>

    <allow users="?"/>

    </authorization>

    </system.web>

    </configuration>

    to your Web.config. If you're already blocking anonymous users, one trick is to create a second Web.config in your Scripts folder with that authorization.

    Courtesy of www.brianhawkinstech.com/.../144-jquery-erro

    Jeff — March 22, 2012 5:28 PM

» Leave a Comment