AJAX PHP标头401

So I am submitting form data on the main page with ajax to a php script that inserts all the data into the database. After finishing though I want to redirect somewhere. So here's my ajax:

$('#form').submit(function() {
    if(val.form()) { 
    var $this = $(this);
        $.ajax({
            data: $this.serialize(), // get the form data
            type: "POST",
            url: "scripts/insert.php",
            complete: function(response){
                var redirect = response.getHeader('Location');
                alert(redirect);
            }
        });
    }
    return false;
});

And at the end of the php file i have:

header("Location: http://www.google.com", true, 401);
exit();

I use chromephp to debug so when executed the console outputs this:

POST http://www.domain.com/Folder/scripts/insert.php 401 (Authorization Required) jquery.min.js:2

Uncaught TypeError: Object #<Object> has no method 'getHeader' /Folder/:320

So how do I redirect at the end of the script when I'm using ajax? Thanks

Try that:

<?php  
ini_set('display_errors', false);  
echo ('Location: http://www.google.com');
?>

It worked for me.

JavaScript:

 $.ajax({
  type: 'POST',
  url: "http://localhost/test.php",
  data: {name: name },
  success: function(output){ window.location = output; }
  dataType: dataType
});