views:

414

answers:

1

Before I throw something ugly together I thought this would be a good one to ask the experts.

So I've got a button that a user can click that:

a) Passes a variable from the element to a jquery function and posts to a php script like so (this works fine, though 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) The PHP script takes the variable, stips/trims/escapes/whatever, checks permissions, and unsets a 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 issue that I'm running into is that I can't just use a header to forward to my page since I'm posting this via ajax. Instead the function is pulling a get of the http://localhost/foo/reviewfoo.php, which doesn't do any good.

Can someone offer some guidance on what might be the best way to do this? I've got some sloppy ideas, but I'm hoping someone can give me an idea on what me be the RIGHT way to do this.

+6  A: 

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

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

Alternatively, if the user is going to be redirected anyway, just do a non-ajaxy form submission.

karim79
Ya, that's about right.
Justin Johnson