Jquery Is Not Getting Registerd

i am using jquery inside my view.php but it’s throwing error like Uncaught ReferenceError: $ is not defined. it mean Jquery is not getting register…

i don’t know what’s going wrong with this code… please suggest me what i am doing wrong here…




      <?php Yii::app()->clientScript->registerCoreScript('jquery'); ?>

<script>

    $(document).ready(function(){

                console.log("Hi am here...");

            })

    function dele()

    {

       $.ajax({

           url : '/test/index.php/test/delete',

           data : '',

           type : 'POST',

           success : function(data)

           {

                  alert(data);

           }

       });

    }

    

    function edi()

    {

        $.ajax({

            url : '/test/index.php/test/edit',

            success : function (data)

            {

                alert(data);

            }

        });

    }

</script>


<?php


$model = new User();

        $q="select * from user where uid=".$id;

        $ulist=Yii::app()->db->createCommand($q)->queryAll();

        foreach ($ulist as $a)

        {

           $ab='<label>Username</label><input type="text" value="'.$a['uname'].'" id="uname"/><br/>';

           $ab.='<label>Password</label><input type="text" value="'.$a['password'].'"/><br/>';

           echo $ab;

        }  

       

?>

<input type="button" value="Delete" name="delete" onclick="dele()"/>

<input type="button" value="Edit" name="edit" onclick="edi()"/>

<div id="msg" style="color: green">

    

</div>

<div id="error" style="color: red">

    

</div>



if i want to register jquery.js file then how to do it?

[size=2]Try like this[/size]




<?php 

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

  $cs->registerScriptFile(Yii::app()->request->baseUrl .'/js/jquery-1.8.2.min.js');

?>



[size=2]same error… Please check i updated my question with rest code… u may get some idea[/size]

Check this thread with a similar problem for some ideas - http://www.yiiframework.com/forum/index.php/topic/28299-

[size=2]Hi You can just include a latest jquery it’s solved.[/size]




<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>

<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>

please give on local


<script src="abc/js/jquery.js"></script>

is working fine… but when i am trying to add using yii it’s not working…

i have went through that post but there he deleted assets folder contains… if i also delete then will it effect to my project?

this way is working. now i am using this way only… but i don’t know why inbuilt is not working?

try this


<script type="text/javascript" src="<?php echo Yii::app()->baseUrl ?>/js/jquery.js"></script>

Basically $ is an alias of jQuery() so when you try to call/access it before declaring the function, it will endup throwing this $ is not defined error . This usually indicates that jQuery is not loaded and JavaScript does not recognize the $. Even with $(document).ready , $ is still going to be undefined because jquery hasn’t loaded yet.

To solve this error:

Load the jQuery library at the beginning of all your javascript files/scripts which uses $ or jQuery, so that $ can be identified in scripts .

There can be multiple other reasons for this issue:

  • Path to jQuery library you included is not correct
  • The jQuery library file is corrupted
  • Working offline
  • Conflict with Other Libraries