Yii Framework Forum: jQuery errors when using GoogleAPI version - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

jQuery errors when using GoogleAPI version Rate Topic: -----

#1 User is offline   M Wotton 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 01-November 09

Posted 15 April 2010 - 12:53 AM

Hi folks,

I am using jQuery quite heavily in my project, and as with most projects I do, I have included jQuery via the Google API rather than the Yii scriptMap.

$cs=Yii::app()->clientScript;
$cs->scriptMap=array(
    'jquery.js'=>false,
    'jquery.ajaxqueue.js'=>false,
    'jquery.metadata.js'=>false,
);
echo CGoogleApi::init(); 
echo CHtml::script(
    CGoogleApi::load('jquery','1.4.2') . "\n".
    CGoogleApi::load('jqueryui','1.8.0') . "\n" 
); 


This reduces load time for our users since they often have this jQuery file already cached from other sites, plus it reduces bandwidth load on our server. I have used it without issue for months, even transitioning from jQuery 1.3.2 to 1.4.2 before Yii 1.1.1 was released.

Now however, I have just been trying to implement CGridView in one of my admin views, and I am getting errors which I am struggling with.

jQuery is not defined
http://www.....com/assets/8c95b397/jquery.ba-bbq.js
Line 814


jQuery is not defined
http://www.....com/assets/28d1d516/gridview/jquery.yiigridview.js
Line 169


and finally

jQuery("#yw0").yiiGridView is not a function
http://www.....com/<controller>/<action>
Line 144


At first I thought it might be an issue with Yii 1.1.0 and jQuery 1.4.2, but I have since upgraded to 1.1.1 and the problem remains.

If I remove the first codeblock I pasted here, the problem goes away, but I really don't WANT to use jquery from Yii - I want to use the Google API version for the reasons I specified above. It seems as if the problem MIGHT be caused by the absence of jquery.yii.js, but is there a way to have this included from my application without inclusing the jQuery library as well?
Micha Wotton
Posted Image
0

#2 User is offline   M Wotton 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 01-November 09

Posted 15 April 2010 - 01:30 AM

Looks like I have answered my own question. This is my new code block from the top of the main layout file:

$cs=Yii::app()->clientScript;
$cs->scriptMap=array(
    'jquery.js'=>"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js",
    'jquery.ajaxqueue.js'=>false,
    'jquery.metadata.js'=>false,
);
echo CGoogleApi::init(); 
echo CHtml::script(
    CGoogleApi::load('jqueryui','1.8.0') . "\n" 
);


While it does not use the Google API, the end result is the same, except that the Yii script dependency chain is not broken (which I found in framework/web/js/packages.php).
Micha Wotton
Posted Image
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users