I have this html code:
<form name="input" action="html_form_action.asp" method="post" id="formID">
Username: <input type="text" name="user" />
<input type="submit" value="Submit" />
</form>
<script>
for (i=0;i<10;i++) {document.getElementById('formID').submit; }
</script>
I'm trying to submit the same thing several times.
But as you can guess, it always submits once, and refresh the page.
How can I avoid this and submit as many times I want?
Use AJAX to send requests silently to the server (i.e. without a refresh).
or instead of submitting the form 10 times, why not move the loop into your ASP file - your form submits once and something happens 10 times over on the server.
What are you trying to do?
In addition to using Ajax, you could also set the target of the form to "_blank", causing the form to submit to a new window or tab.
<form target="_blank" name="input" action="html_form_action.asp" method="post" id="formID">
The browser can open as many windows as you let it so you could go on for a while.
This would be incredibly annoying to a user though. I hope you know what you're doing.
You must submit form by Ajax. use JQuery.Ajax
$(function(){
$.ajax({
url:'html_form_action.asp',
data: $("form").serialize(),
// other setting
success: function(){
// what you do after post
}
});
});
visit: http://api.jquery.com/jQuery.ajax/ for other setting
Try this:
$('form[name="formname"]').submit(function(){
form = $('form[name="formname"]').serialize();
url1 = 'http://...';
url2 = 'http://...';
$.ajax({
url:url1,
type:'POST',
data:form,
success:function(result){
$.ajax({
url :url2,
type :'POST',
data :form,
success :function(result){
}
});
}
});
return false;
});
Replace formname with the name of the form
Peplace url1 and url2