Is there an “after submit” jQuery option?

后端 未结 4 564
执笔经年
执笔经年 2020-12-03 02:31

I have a form that uploads a file and targets an iframe on the page. When the user clicks submit, I want the file contents to \"clear\" out.

I tried this

<         


        
相关标签:
4条回答
  • 2020-12-03 03:04

    If you have no other handlers bound, you could do something like this:

    $('#imageaddform').submit(function(e) {
        e.preventDefault(); // don't submit multiple times
        this.submit(); // use the native submit method of the form element
        $('#imagefile').val(''); // blank the input
    });
    
    0 讨论(0)
  • 2020-12-03 03:13

    How are u submitting the form? if this is normal form post then then page wont exist in that case i am wondering if u are looking to clear the form before the page refreshses so that when the user comes back he doesn't see the values populated.

    If the form is submitted by ajax then you can

    function(){
     $('form1')[0].submit();
     clearForm();
    }
    

    Did i miss the question?

    0 讨论(0)
  • 2020-12-03 03:14

    Lonesomeday's solution worked for me but for Google Chrome I found it would still submit empty form data unless I added a timeout like this:

    $('#imageaddform').submit(function(e) {
        e.preventDefault(); // don't submit multiple times
        this.submit(); // use the native submit method of the form element
    
        setTimeout(function(){ // Delay for Chrome
            $('#imagefile').val(''); // blank the input
        }, 100);
    });
    
    0 讨论(0)
  • 2020-12-03 03:14

    You could do something like this:

    $('#imageaddform').submit(function(){
      setTimeout(function() {
        $('#imagefile').val('');
      },100);
    });
    
    0 讨论(0)
提交回复
热议问题