Reputation: 97
I am getting this err
Uncaught ReferenceError: $ is not defined.
I have searched and found that the usual cause of this is not having jQuery declared in the right place but I think I have it right.
Thanks in advance.
<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="ajax2.js"></script>
<script type="text/javascript">
var slideimages = new Array() // create new array to preload images
slideimages[0] = new Image() // create new instance of image object
slideimages[0].src = "images/aib.jpg" // set image src property to image path, preloading image in the process
slideimages[1] = new Image()
slideimages[1].src = "images/paddypower.jpg"
slideimages[2] = new Image()
slideimages[2].src = "images/rtegaa.jpg"
slideimages[3] = new Image()
slideimages[3].src = "images/ssgaa.jpg"
$(document).ready(function(){
function get_weather()
{
var p = $("#code").val();
var u = ($('#u').attr('checked')) ? '&u=c' : '';
var to_load = 'get_weather.php?p='+ p + u;
$("#weather").html('<img style="margin-top: 104px;" src="ajax-loader.gif" align="absmiddle">');
$("#weather").load(to_load);
}
$(window).load(get_weather); // Trigger "get_weather" when the window loads
// Trigger "get_weather" when the form objects are used
$("#code").change(get_weather);
$("#u").click(get_weather);
});
Upvotes: 0
Views: 4965
Reputation: 1443
This error will not occur if the file "jquery-1.2.6.min.js" is not present in the location mentioned in your script tag. From your code, the jquery file should be present in the same folder as your startup page.
I'll check the following things when this error occurs
1) Make sure the jquery script file is present in the correct location
2) Name of the jquery file is same as referenced in script tag
3) In browsers console window, there is a debugger or source tab which shows all the script and CSS files used by the page. Check jquery is present under the sources tab of the browser
Upvotes: 0
Reputation: 4241
Probably you called jQuery.noConflict()
somewhere.
To solve this, wrap your code like this:
(function($, undefined){
if( !$ )
{
console.log('jQuery failed to load');
return;
}
//jquery code here
})(window.jQuery);
This will prevent the jQuery.noConflict()
from affecting your code and you can debug in case jQuery is having some troubles.
Also, watch your 'Network' tab, on the Element Inspector (press F12).
Upvotes: 1
Reputation: 903
The solution:
1) Use Google CDN to load jQuery
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
2) It is compatible with jQuery v1.5-v1.7 because most of the methods were deprecated in jQuery 1.8+. This is the reason I've used v1.5 of Google CDN jquery in point 1. Most of the examples on cycle plugin use jquery 1.5.
3) Clear Your browser cache, It is the main culprit most of the times.
4) PLease check the loading of jquery using the code below
if(typeof jQuery!=='undefined'){
console.log('jQuery Loaded');
}
else{
console.log('not loaded yet');
}
Upvotes: 4