How can we send a request using the HTTP POST method via javascript...without submitting a form?
+10
A:
I prefer to use jQuery.post() - for example:
$.post("test.php", function(data){
alert("Data Loaded: " + data);
});
Justin Ethier
2010-07-16 18:33:51
Who doesn't :-)
Darin Dimitrov
2010-07-16 18:34:28
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)
Kathy Van Stone
2010-07-16 18:35:54
Absolutely, but at this point anyone working with JavaScript needs a good reason for NOT using a library such as jQuery.
Justin Ethier
2010-07-16 18:37:49
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.
lucideer
2010-07-16 19:25:39
A:
<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>
Gregory Belton
2010-09-24 21:22:18
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.
Gregory Belton
2010-09-24 21:24:53