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

I have this php file:


echo $_POST;



   type: "POST",

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

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

   success: function(msg){ 




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){ 


       window.location.href = response.url;


or you could hardcode url:

 success: function(msg){ 


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


1 Like