0

I need to redirect to a php page with informations by POST when a user click on an image.

Here's the way I do it for now :

function redirect(id) {
   var url = 'newPage.php';
   var form = $('<form action="' + url + '" method="post">' + 
                    '<input type="text" name="prankId" value="' + id + '"/>' +
                '</form>');
   $('body').append(form);
   form.submit();
}

With Javascript, I create a form with my input and I submit it. But when i reload the page (that I redirected to), it ask me to resubmit my form. Is there a way to do it where I wouldn't have to resubmit it?

Antoine Grandchamp
  • 5,651
  • 2
  • 26
  • 34
  • Why are you *re-loading* the page you wind up on? – Malovich Nov 30 '16 at 21:16
  • "resubmit data" means that something was posted. If you want to not have someone resubmit the data, in php, use the post data, do stuff, store the result in a session and then do a header redirect. After the redirect, you can access the data from session to build the page. – Jonathan Kuhn Nov 30 '16 at 21:17
  • 2
    Possible duplicate of [JavaScript post request like a form submit](http://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit) – mhodges Nov 30 '16 at 21:17
  • @JonathanKuhn Thanks, I will do it with session variables – Antoine Grandchamp Nov 30 '16 at 21:29

1 Answers1

0

You can use GET instead of a POST request or you can use POST/REDIRECT/GET pattern.

Tanmoy Majumdar
  • 409
  • 3
  • 6