以下表单允许用户上传图片:
<form id="form" action="upload.php" enctype="multipart/form-data" method="post">
<input type="file" id="file" name="file" onchange="submitForm()">
</form>
我希望用户选择其文件后立即提交此表单,因此在javascript中我做了
$(document).ready(function(){
$("form").on('submit',function(e){
console.log("It works");
});
});
function submitForm()
{
$('form').submit();
}
哪个有用!
我知道希望我的用户在提交表单后留在当前页面上,我尝试在提交表单后立即添加回调函数:
function submitForm()
{
$('form').submit(function(e){
e.preventDefault();
});
}
但是我的表格没有提交......
我也想知道如何获得ajax调用的结果?