2

i have a button and onClick I want to move to a different page passing data with POST method.

My actual code is the following and will accomplish to redirect using GET method.

How to do it with POST? I know I can do it with a form, but I can't figure out what is the lightest way to insert a form in my code.

$('.compila').click(function(e){
  e.preventDefault();
  var id_form=$(this).data("value");
  console.log(id_form);
  location.href="form_builder.php?id="+id_form;
});

Edit: I have found some similar questions but very outdated. One is suggesting to use a plugin and it is more than 5 years old. I'd prefer to do it without plugins anyway

Lelio Faieta
  • 6,457
  • 7
  • 40
  • 74
  • `window` methods can only redirect via GET. If you absolutely have to move to the next page via POST then you'll need to dynamically build a `
    ` element and submit it.
    – Rory McCrossan May 04 '20 at 16:49
  • @RoryMcCrossan even older than those I was looking for but should work. Thanks :-) – Lelio Faieta May 04 '20 at 16:55
  • No problem. This issue hasn't changed in years as the web is supposed to only work with GET requests when navigating. – Rory McCrossan May 04 '20 at 16:56

0 Answers0