won't redirect anymore - 302 status code

354
November 22, 2016, at 10:02 AM

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();
    }
});
Answer 1

You cannot redirect the page within an ajax request. You can use JQuery redirects instead.

Rent Charter Buses Company
READ ALSO
Getting TypeError when iterating over an object

Getting TypeError when iterating over an object

I am using Rails, and I am getting an error in my jQuery code:.

351
Having multiple countdown timer in javascript with dynamic arguments

Having multiple countdown timer in javascript with dynamic arguments

I have implemented multiple countdown timer by using this jsfiddle link.

502
Passing Array to WebMethod using jquery ajax is not working in asp.net

Passing Array to WebMethod using jquery ajax is not working in asp.net

I am trying to send all gridview records to webmethod using jquery ajax but it is not working. Here is my code.

500
Semantic UI adding class dynamically to input field

Semantic UI adding class dynamically to input field

It seems there is an issue with adding class dynamically to input field in SUI. .

816