Question

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.

Was it helpful?

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.

OTHER TIPS

You should include jquery in all controller/action, to do that, insert this code to Controller.php (most parent of all controller in application)

public function beforeAction($action)
   {

      $cs = Yii::app()->clientScript;
      $cs->registerCoreScript('jquery');

   }

I had the same problem, then I looked into the "View Source", there, the jquery was loaded from assets and from the "js" directory. So I removed the registerScriptFile('js/jquery'); . Then it was working fine as it loaded jquery only from assets.

I just had a similar problem, after I'd set components -> assetManager -> linkAssets to true to ensure the "latest" version of assets were being used. I then forgot, and wiped my assets folder, which removed all the original assets!

Handily I was able to revert the originals (version control ftw) and all was restored. Might be useful to others in a similar predicament.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top