3

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

3 Answers 3

10

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

$.post("test.php", function(data){
  alert("Data Loaded: " + data);
});
Sign up to request clarification or add additional context in comments.

3 Comments

That does require adding jQuery to your system (although if you are going to use AJAX it is much easier if you use some library package)
Absolutely, but at this point anyone working with JavaScript needs a good reason for NOT using a library such as jQuery.
Hmmm.. the fact that my Javascript code is almost always far smaller than the massive 24kb (not including plugins) I need to load to use jQuery would be a fairly good reason imho.
9

By using AJAX.

Comments

-1
<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 Comment

Sorry just read you put without submitting the form!! You can use Prototype.js, it has a form.serialize method. You can then use a Prototype Ajax call to send the data to the server without submitting the page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.