Ajax (jquery) vs php redirect ideas?

Before throwing something ugly together, I thought it would be good to ask the experts.

So I have a button that the user can click on:

a) Pass variable from element to jquery function and submit to php script like so (this works great, although there is probably an easier way):

$(".complete_btn").live("click", function(){
    var fooString= this.id;                                 
    var fooSplit= fooString.split("-");
    var fooId= fooSplit[1];
        $.ajax({
            type: "POST",
            url: "http://localhost/foo/php/complete_foo.php",
            data: "fooId="+fooId,
            success: function() {
                }
            });
})

      

b) PHP script takes a variable, stips / trims / escapes / whatever, checks permissions and disconnects the session and creates a new one (also works fine):

if(isset($_SESSION['foo_id']))
                    unset($_SESSION['foo_id']); 
                    session_start();
                    $_SESSION['foo_id'] = $foo_id_posted;
                    header ("Location: http://localhost/foo/reviewfoo.php");

      

The problem I am running into is that I cannot just use the header to post to my page, since I am posting this via ajax. Instead, the function pulls in get

http: //localhost/foo/reviewfoo.php , which doesn't do any good.

Can anyone suggest some guidance on what might be the best way to do this? I have sloppy ideas, but I hope someone can give me an idea of ​​how I should be RIGHT.

+2


source to share


1 answer


In the success function of your ajax call, you can redirect the user:

success: function() {
             window.location.href = 'http://localhost/foo/reviewfoo.php';
         }

      



Alternatively, if the user will be redirected anyway, just do a non-aaxic form submission.

+7


source







All Articles