In a php file i have used include
to include the following js.php file
and prior to that i have included the jquery file.
I had such Problem, Just changed <script type="text/javascript">
to <script type="javascript">
and all problems gone!
Just had this crop up and it turned out to be a spelling mistake in the script tag:
<script type="text/javscript">
Note the missing 'a' in javascript. Changing to simply:
<script>
Fixed the problem.
Yes, i noticed that sometimes is problem with that, i wrote safe solution for that, which fix this problem.
// jquery plugin 'jquery.ready.fix.js'
// @author Szymon Działowski
;(function ($) {
$.fn.ready.old || $(function (r) {
r = $.fn.ready;
$.fn.ready = function (fn) { $.isReady ? fn() : r(fn); };
$.fn.ready.old = r;
});
})(jQuery);
after that you can run code:
$(function () {alert('go')})
and it always fire alert.
PS: it is a technique called "duck punching" more about: http://www.paulirish.com/2010/duck-punching-with-jquery/
Another cause that will silently fail, and all remaining callbacks never called:
$(document).ready(null);
So check if you have variables or syntax errors that return null. Like this one:
$(document).ready(function($){}(jQuery));
Notice that the function above is called instantly and undefined is returned.
Also look out how you define the jquery include tag. It seems for some reason you need to open and close the tag with two seperate tags. Using one tag with closing it seems not to work:
Works:
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
Doesn't work:
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"/>
Another point to check: Maybe you have a PHP error in your program. A PHP Fatal error exits the script and $(document).ready
will never be executed.
Depending on your server settings or on your CSS you might not see the Fatal error message.