IE 7 + jquery 1.3.2 errors
I have the following code in my page. Sometimes the jQuery is loading fine but sometimes i get an error: jQuery is undefined
<script src="/javascripts/jquery-1.3.2.min.js" type="text开发者_如何学C/javascript"></script>
<script src="/javascripts/jquery-ui-1.7.1.custom.min.js"
type="text/javascript"></script>
<script type="text/javascript">
alert('test')
var $j = jQuery.noConflict();
alert('test1')
//start when document is ready
$j(document).ready(function(){
alert('test2')
When jQuery does not load I only see first alert
on the page. So I am thinking jQuery is never loaded. Also I am using the noConflict just because before I was getting error $ is undefined
. I am not using any other js library like prototype or anything. So I don't have any REAL need to use jQuery noConflict()
Has someone come across these kind of problems with jQuery and IE 7? This error is not happening on Firefox.
Can something be done to fix this?
Update I decided to make use of jQuery + jQuery UI hosted on Google. which worked for me.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" type="text/javascript"></script>
If you don't have any other conflicting libraries, then $ is undefined
pretty much means either your script library path for jquery is incorrect, or that jQuery isn't ready yet. There's no reason in this case to use the no conflict functionality.
Try this:
<script src="/path to your/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
alert("jquery is ready.");
});
</script>
If the alert fires, you know jQuery is referenced and initialized properly.
If not, try these options:
- Try using Firefox with Firebug to check that the script path is correct (you'll be able to actually load up the script file in the firebug pane)
- Use the non-minified version of jQuery in development, to ensure there are no issues there
If this happens in other browsers as well, then my first bet is your URL paths to the Jquery libraries are incorrect. (javascripts
or javascript
). Try putting the full URL to the library and see what happens.
Is the noConflict declaration correct? I think it should be
var j = jQuery.noConflict();
....
j(document).ready(function(){....}
精彩评论