• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 602
  • Last Modified:

Return data to Ajax from PHP file

I have a form that submits data through AJAX to a PHP file.  (register-code.php) (www.celsyouth.cenational.org/register/index.php) The PHP file saves the data to a mysql database.  Once the PHP file is completed, I'd like to post an ID number back to the AJAX call to send it to another PHP file where the user will have the option of paying by credit card.  Here's the AJAX code...

submitHandler: function(form) {
            var dataString = $(form).serialize();
                            data: dataString,
                            cache: false,
                            success: function(data){
                            window.location.href = 'registrationComplete.php?ID=$var_id'; 
							error: function( jqXHR, textStatus, errorThrown){
								alert("Error:" +textStatus);

Open in new window

I can 'echo' the data back to the AJAX function, but how do I pass the ID into registrationComplete.php?

Thanks for all the help in advance.

1 Solution
success: function(data){
     if(data.status) window.location.href = 'registrationComplete.php?ID=' + data.id; 

Open in new window

and in register-code.php you've at the end if the registration is complete:
echo '{"status":true,"id":"' . $id . '"}';

Open in new window

but why not storing this ID in the session, it's more secure?
$_SESSION['id'] = $id;
and just return status (true or false)
stkoontzAuthor Commented:
Thanks  leakim971.  Sometimes the simplest solution is the best.  The session variable is working great.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now