JQuery: Send Post Data and Redirect

Mar 2, 2015
Basically, what I wanted to do is to send data from one page to another page.
Apparently, I don't have any form to submit and I don't want it to appear on the URL, either.

Here's one simple solution:


var form = $("<form action='" + url + '' method='post'>" +
  "       <input type='hidden' name='id' id='id' value='" + id + "'/>" +
  "       <input type='hidden' name='username' id='username' value='" + username + "'/>" +
  "</form>");
$('body').append(form);
form.submit();


where id and username are variables holding the data you want to send to another page, and url is the page you want to pass the data to.

Any other alternate solution?

Please feel free to leave your message on the comments section.

No comments:

Post a Comment