Please tell me there is such a code:

<input type="text" name="id" value="текст" hidden> <a href="/delete.php?id=">Отправить</a> 

How to take data from input and send to link? post and get forms are not suitable. Is it possible to perform a post request using ajax? How to perform a post or get request using ajax without <form></form> ? This data / /delete.php should be hidden.

  • So how do you want to get data via $ _GET or $ _POST? - doox911
  • @ doox911 if it is possible without <form> </ form> tags then yes - Vladislav Samokhin
  • yes you can. I ask what method? If you want to hide the data transfer, you must pass through the post. - doox911

2 answers 2

If I correctly understood what you want, then something like this.

 document.getElementById("send").addEventListener("click", function(){ let value = document.getElementById("data").value; let xhttp = new XMLHttpRequest(); xhttp.open("GET", "/delete.php?id=" + value, true); xhttp.send(); }); 
 <input id="data" type="text" name="id" value="текст" hidden> <a href='#' id="send">Отправить</a> 

  • Why is the button not active - Vladislav Samokhin Nov.
  • Do not tag <a>, a button. I corrected in the answer. - Lukas Nov.
  • See, the point is that you need to follow this link with the value of input, where php then takes the data. - Vladislav Samokhin
  • That is, it is necessary to follow the link and so that there is no link there? Or just need to click, so that the data went to the back? - Lukas
  • It is necessary to follow the link and that this link would not exist. - Vladislav Samokhin

Perhaps through ajax.

 $.ajax({ method: "POST/GET", // Выберите нужный метод url: "/delete.php", data: {data = $('input').val()}, success: function(result){ alert(result); } }); 
  • And it is important not to forget to connect jQuery;) - Lukas
  • Tell me how to call this function? - Vladislav Samokhin Nov.
  • You can call a function on any event, for example, pressing the $ ('button') button. Click (function () {$ .ajax (...)}) - Sergey Dymov