call an action each second

Hello, I want to call an action each seconds.

My controller is:

class AlarmaController extends Controller



public function actionValidarTimeOutSMS(){


            $val1 = $_POST['val1'];

            $val2 = $_POST['val2'];

            echo "something.. HELLO";





and my view is:

<script type="text/javascript">


                    setInterval(alertFunc, 3000);


            function alertFunc() {


                    type: "POST",

                    url:    "<?php echo Yii::app()->createUrl('alarma/ValidarTimeOutSMS'); ?>",

                    data:  {val1:1,val2:2},

                    success: function(msg){



                    error: function(xhr){








it never show me something… HELLO

Thanks you for your help, I rally I need that it work…

You may have not loaded the jQuery. Your code is working fiddle at

I tryed it but It’s not work. It show me the erros message: failure4<?php echo Yii::app()->createUrl(‘alarma/ValidarTimeOutSMS’);?>

If you check it using the network you will see the ajax request sent. You are getting the error because the url is not there. So 404 error occurs.