Using jQuery Form, for some reason I have to submit a form through jQuery on method like this:
$("#submitImage").on("click", function() {
$('#loaderForm').ajaxForm(function() {
alert("Uploaded SuccessFully");
});
});
but this is not submitting the form! Can you please take a look at this demo and let me know what i am missing or doing wrong here?
$("#uploadFile").change(function() {
$('#image_preview').html("");
var total_file=document.getElementById("uploadFile").files.length;
for(var i=0;i<total_file;i++)
{
$('#image_preview').append("<img src='"+URL.createObjectURL(event.target.files[i])+"'>");
}
});
$("#submitImage").on("click", function() {
$('#loaderForm').ajaxForm(function()
{
console.log("Uploaded SuccessFully");
});
});
input[type=file]{
display: inline;
}
#image_preview{
border: 1px solid black;
padding: 10px;
}
#image_preview img{
width: 200px;
padding: 5px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.2.2/jquery.form.min.js"></script>
<div class="container">
<form id="loaderForm" action="uploadFile.php" method="post" enctype="multipart/form-data">
<input type="file" id="uploadFile" name="uploadFile[]" multiple/>
</form>
<br/>
<button type="button" class="btn btn-success" id='submitImage' >Upload Image </button>
<div id="image_preview"></div>
</div>
type of button should be 'submit'