php – redirect ajax requests

How can I redirect an ajax request in php/wordpress.

I tried header("Location: " . "http://redirect.url"); but it doesn’t work, the response has 301 Moved Permanently status and the request fails.

Related posts

Leave a Reply

1 comment

  1. You cannot redirect from php by an ajax request. Instead of that you need to do it inside your javascript.

    For example if this is your ajax then after success of your request redirect from ajax itself

    $.ajax({
        type    : 'post',
        url     : 'http://localhost/redirect.php',
        success : function(data){
           window.location = "http://your/url";
        }
    });