jQuery error: jquery not being defined

Hello all,

I’ve started this topic in order to get some answers about jquery within Yii. the first question is going to be the most simple one and yet, it needs answering because I’m stuck:

I’m trying to display an alert using jquery just to see if it works, but i don’t get any alert message. The code is as follows:




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


Yii::app()->clientScript->registerScript('helloscript',"

        alert('hello');

    ",CClientScript::POS_READY);



Could anyone see an error in my code? Is there a flag or something that I need to set up before using this code?

Thanks a lot!

Alejandro.

If I copy/paste the code into a yii default application it works for me.

Did you check the html output sourcecode …?

Did you check the console /javascript errors in your browser…?





<head>

...


	<script type="text/javascript" src="/yii/desticard/assets/4435e95e/jquery.js"></script>

<title>My Web Application</title>

</head>







...

</div><!-- page -->


<script type="text/javascript">

/*<![CDATA[*/

jQuery(function($) {


        alert('hello');

    

});

/*]]>*/

</script




http://www.yiiframework.com/forum/index.php?/topic/13596-jquery/page__view__findpost__p__128532

Thank you for the responses.

I was making a mistake by exitting the application in the view file after the jquery code definition. Removing the ‘exit;’ line from the view fixed the problem.

Thanks a lot!!

Alejandro.

Thanks for the reply. The problem was in the view code and it’s fixed now!

Alejandro.

Forgot to mention that @samdark got the solution to the issue.

I’d like to thank all of those who posted back in this topic or sent me private messages to help find the solution to my problem.

The topic could now be closed.

Alejandro.