そのため、すべてのデータをデータベースに挿入するphpスクリプトにajaxを使用して、メインページのフォームデータを送信しています。終了後、どこかにリダイレクトしたいのですが。だからここに私の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;
});
そして、私が持っているphpファイルの最後に:
header("Location: http://www.google.com", true, 401);
exit();
私はchromephpを使用してデバッグするので、実行するとコンソールは次のように出力します:
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
では、ajax を使用しているときにスクリプトの最後でリダイレクトするにはどうすればよいでしょうか。ありがとう