Reputation: 911
this is my html form
<form id="contactForm1" method="POST" action="downloadfile">
<input id="tesst" name="tesst" type="hidden" value="<?php echo $val['file_name'];?>"/>
<div id="download" class="btn btn-danger">Download</div>
</form>
And here is the Jquery function
var frm = $('#contactForm1');
frm.submit(function(ev) {
$.ajax({
type: frm.attr('method'),
url: frm.attr('action'),
data: frm.serialize(),
success: function(data) {
alert('ok');
}
});
ev.preventDefault();
});
I don't know much about Jquery.
Please anybody can help me with this?
Thanks.
Upvotes: 1
Views: 439
Reputation: 10994
There are 2 ways to solve your problem
div
(download button) to a input submit
button and leave your script as it isExample: http://jsfiddle.net/Spokey/bNa7d/
var frm = $('#contactForm1');
$('#download').click(function (ev) {
$.ajax({
type: frm.attr('method'),
url: frm.attr('action'),
data: frm.serialize(),
success: function (data) {
alert('ok' + data);
}
});
});
Upvotes: 1
Reputation: 38102
Two things
You need to add input
submit element to your form
Change action="downloadfile"
to action="downloadfile.php"
if your downloadfile.php
is the same directory with your current HTML file.
Upvotes: 1