jquery IE8 $(document).ready "object expected" error

19.4k views Asked by At

I'm having a problem with IE8 throwing an "object expected" error when loading a page with the jquery command $(document).ready(). I've gone through all the other posts I can find here on SO, and none of the solutions seem to work.

To troubleshoot, I created the following html, which runs fine in Firefox and Chrome, but produces an "object expected" error at the $(document).ready line. So far:

  1. I've confirmed it is reaching the google jquery file - and tried referencing a local jquery.js file - same result.
  2. Tried placing the script in the <head> (I've included it in the body to recreate the situation on the site I'm developing on)
  3. I've also tried this with jQuery(document) instead of $ - same result
  4. Tried including: var $j=jQuery.noConflict(); and including $j(document), getting a 'jQuery is undefined' error on the $j declaration.

What am I missing? ANY help is appreciated! Thanks!

<html>
<head>
    <script type="application/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
</head>
<body>
    <script type="text/javascript">
        $(document).ready(function(){
    alert("WORKING!");
    });

</script>

<div id="test">
</div>
</body></html>
4

There are 4 answers

6
Alfabravo On BEST ANSWER

Mate, check your two script tags. One says type="application/javascript", the other says type="text/javascript".

Change the first one to type="text/javascript" and it will work fine.

0
Roman Losev On

The thing helped me replacing

type="text/javascript" 

into

language="javascript"
0
Schmutz On

Just encountered this error as well.

The problem on my part was pretty dumb: I ran the Internet Explorer in a Virtual Machine. This machine didn't have access to the Internet but only to the host system where I had the webserver running. Therefore, the external script references could not be resolved of course.

0
Jakob Ojvind Nielsen On

Had the same problem. I fixed this by struggling hard for some time and tried a bunch of thinks that did'nt work. But this work:)

Check you jquery script tag. If it contains the type="text/javascript" like this

<script  type="text/javascript" src="~/scripts/jquery-1.9.0.js"></script>

then replace the "text/javascript" with only "javascript"

<script type="javascript" src="~/scripts/jquery-1.9.0.js"></script>

Really vierd behaviour but it works. If anyone has a good explanation then please post an answer to this.

NB! This works only for IE8, not for Chrome or Firefox !