Question: I am trying do some file upload using jquery. The upload box have to be in the dialog box.
Now I just want to know after I click on the dialog's upload button. How can I submit yet the page do not load.
I tried using this
$('#uploadForm').submit().preventDefault();
It has not action at all.

**html**

```
<script>
                $( "#dialog-upload" ).dialog({
                autoOpen: false,
                height: 200,
                width: 350,
                modal: true,
                buttons: {
                "Upload": function() {                  
                    var bValid = true;
                    bValid = bValid && checkCSV()
                    if(bValid){
                        **$('#uploadForm').submit().preventDefault();**

                        }
                $( "#dialog-upload" ).dialog( "close" );
                        },
            Cancel: function() {                
                allFields.val( "" ).removeClass( "ui-state-error" );
                $( this ).dialog( "close" );
            }
                },
            close: function() {
                allFields.val( "" ).removeClass( "ui-state-error" );
                $( this ).dialog( "close" );    

                }
                });
</script>

  <div id="dialog-upload" title="Upload csv file">
    <form>
    <fieldset>
        <form action='ajax.php' id = 'uploadForm' method='post' enctype='multipart/form-data'>
        <input type="text" name="file" id="fileUpload" size = 30 class="text ui-corner-all" />
        </form>
    </fieldset> 

    </form>
</div>

```

**php**

```
if (isset($_FILES['file'])) {
echo "success";
}

```

Answer: 
Use the `EVENT` delegation for your form submit

```
$('#uploadForm').submit(function( e ){
  e.preventDefault(); // browser 'submit' event behavior prevented
});

```

Than do:

```
"Upload": function() {                  
    var bValid = true;
    bValid = bValid && checkCSV()
    if(bValid){
       $('#uploadForm').submit();
    }
    // ......

```
You can bind something to the submit event prior to submitting.

```
$(function() {
    $('#uploadForm').submit(function(evt) {
        evt.preventDefault();
    });
});

```

Then just call .submit() without the preventDefault() in your original location.