How can we send an HTTP POST request using JavaScript?

How can we send a request using the HTTP POST method via javascript ... without submitting the form?

+3
source share
3 answers

I prefer to use jQuery.post () - for example:

$.post("test.php", function(data){
  alert("Data Loaded: " + data);
});
+10
source
+9
source
<form id="myform">
<input type="text" name="weather" value="sunny" />
</form>

<a href='javascript:submit_form()'>Click here to submit the form</a>

<script language='javascript'>
function submit_form()
{
   var myform = document.getElementById('myform');
   myform.submit()
}
</script>
-1
source

Source: https://habr.com/ru/post/1755034/


All Articles