Hey guys I got a 302 error code when I want to redirect my page, I'm using header()
I searched over google if I could find anything but I found nothing that was relevant for me, so maybe you guys can find it ;)
I get in the network
tab in element inspecting
2 responses 1 is of my posting
function in jQuery
and the other is of the header('Location: index.php');
and that gives a response within Reload page to pick up source code for: http://localhost/porfolio/index.php
I did the header('HTTP/1.1 200 OK');
cuz I saw it would force it to give it a 200 OK code. But when I did that it didn't even give the response of the header('Location: index.php');
I just wan't to redirect the person to index.php when he submitted and all fields are oke.
Response:
if (!empty($error))
{
foreach ($error as $errors)
{
echo '<span class="glyphicon glyphicon-warning-sign" style="padding-right:5px; color:red;"></span><a class="errors" style="color:red;">' . $errors . '</a><br>';
}
}
else
{
header('Location: index.php');
header('HTTP/1.1 200 OK');
}
Request
posting.done(function(data){
var errors = $('<div>' + data + '</div>').find('.errors');
if (errors.length > 0)
{
$("#gb-errors").slideDown().empty().append(data);
}
else
{
$("#gb-errors").slideUp().empty();
}
});
You cannot redirect the page within an ajax request. You can use JQuery redirects instead.