Search code examples
jqueryyiiyii-components

Firebug error: jQuery is not defined - in yii app


I'm using Yii Framework v1.1.10r3566. I'm noticing in Firebug that the generated code is producing an error. It says "jQuery is not defined" and the line has a function "jQuery(function($)". It is occurring on multiple pages and I believe that it is preventing my zii widgets from operating properly (CJuiDatePicker is not working when previously it had worked). I am not writing any routines using jQuery nor am I including any other javascript library. The generated code on one of the pages that is generating the error is:

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="language" content="en" />
<!-- blueprint CSS framework -->
<link rel="stylesheet" type="text/css" href="/myapp/css/screen.css" media="screen, projection" />
<link rel="stylesheet" type="text/css" href="/myapp/css/print.css" media="print" />
<!--[if lt IE 8]>
<link rel="stylesheet" type="text/css" href="/myapp/css/ie.css" media="screen, projection" />
<![endif]-->
<link rel="stylesheet" type="text/css" href="/myapp/css/main.css" />
<link rel="stylesheet" type="text/css" href="/myapp/css/form.css" />
<script type="text/javascript" src="/myapp/assets/ef86d901/jquery.js"></script>
<script type="text/javascript" src="/myapp/assets/ef86d901/jquery.yiiactiveform.js"></script>
<title>myapp - Login</title>
</head>

I'm at wits end and haven't a clue why the generated code is producing this error. Help would be appreciated.


Solution

  • That error is usually the result of jQuery framework not being installed. It looks like your jquery.js is your jQuery framework since you mention your not using any custom markup yourself.

    A quick test is to replace this:

    <script type="text/javascript" src="/myapp/assets/ef86d901/jquery.js"></script>
    

    With this:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    

    Note to replace 1.7.2 with your required jQuery version as explained by using Google's hot-linked API Libraries.

    If that solves your issue, then check the path to your local jQuery file or consider using Google's hotlinked API Libaries which has other benefits you can read about.