I have a drop down that I select a file type from, I then want it to fire at a page that generates a file depending on what was selected and forces a download of it using header in php. Here’s the jQuery.
$('#exportdropdown').change(function(){
var searchinput = $('#searchinput').val();
var maxrec = $('#navdropdown option:selected').text();
$('.loadCont').fadeIn();
if($('#importbutton').hasClass('clickedButton')){
$.get('export.php', {filter: 'import', maxrecords: maxrec, type: 'xls'});
}else{
$.get('export.php', {filter: 'export', maxrecords: maxrec, type: 'xls'});
}
$('.loadCont').delay('600').fadeOut();
});
I’m forcing the type at the moment for testing, but it doesn’t seem to work how I expected. When you address the file with the data below so export.php?filter='import'&maxrecords=15&type='xls' it forces the download fine. Just not using the jQuery method. Anything obvious that stands out to someone more experienced?
Ajax is pointless here, all you are doing is requesting a link which pushes a file to your browser. Try: