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.
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
ReplyDeleteTHX
Search the problem , your page came up.
ReplyDeleteWorked for me ... thank you.
Thanks Amjad and Ellis, found you after breaking my head for nearly 10 hours on this error and your solution worked. You guys rock!!!!!
ReplyDeleteAmjed, 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.
ReplyDeleteEllis, thanks for sharing info on using declarative syntax to refer to a particular version of jquery.
Good Information, saved my time.
ReplyDeleteThanks Amjed and ellis.
Worked for me! Thanks very much
ReplyDeleteI spent so much time trying to 'debug' this and with a simple drag and drop, my link now works!
ReplyDeleteYou hit the error eactly. It hlped me a lot. thanks
ReplyDeleteJust can not THANK you enough.
ReplyDeleteThis stupid error drove me crazy for days.
Thanks a million .... ! I could help my friend solve this issue which has been consuming him for days :)
ReplyDeleteThanks a lot ... I have spent so much time before I found your usefull page!!!!!
ReplyDeleteI am having the same issues using Internet Explorer 8. FireFox has no issues. Any project i use for Jquery or silver light has issues
ReplyDeleteI 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
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.
ReplyDeleteI 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 - 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.
ReplyDeleteIf 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.
perfect...thank you very much. Drag n drop did not work for me but adding links from google did.
ReplyDeleteThanks a lot, after dragging the jquery its works fine
ReplyDeleteOf course, on my development machine had high security settings so jquery would not work!
ReplyDeleteReset 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.
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.
ReplyDeleteSo 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>
Thanks, it worked. I later found that if you don't want to reference an outside link, you can try adding
ReplyDelete<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
hi,
ReplyDeletegreat post and it's worked fine for me
bhaskar, csharpektroncmssql.blogspot.com