How do you redirect to the layout file after making a POST request?

I have this php file:


<?php


echo $_POST;


...


$.ajax({

   type: "POST",

   url: Yii::app()->createUrl('//newsletter/create'),

   data: { name: "Daniel", phone: "01234123456" },

   success: function(msg){ 

       alert('Success!');

   }

});

How do you redirect to the php file where the ajax request was made after the ajax POST request?

You could return url you want to redirect to from server :




success: function(response){ 

       alert(response.message);

       window.location.href = response.url;

   }



or you could hardcode url:




 success: function(msg){ 

       alert('Success!');

       window.location.href = '<?php echo Yii::app()->createUrl('controller/action');?>';

   }



1 Like