[removed] send multiple submitions

2019-01-19 09:47发布

问题:

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?

回答1:

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?



回答2:

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.



回答3:

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



回答4:

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