我正在尝试使用 jquery 进行一些文件上传。上传框必须在对话框中。现在我只想知道单击对话框的上传按钮后。我如何提交但页面未加载。我尝试使用这个 $('#uploadForm').submit().preventDefault(); 它根本没有动作。
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";
}