2012-04-12 50 views
1

我有一个下拉菜单,我选择一个文件类型,然后我希望它在一个页面生成一个文件,这取决于选择的内容并强制下载它在php中使用header。这里是jQuery。使用jQuery加载一个页面,但不是一个容器div

$('#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(); 
}); 

我强制测试的类型,但它似乎并没有工作,我的预期。当您使用以下数据访问文件时,它会强制下载正常。只是不使用jQuery方法。任何显而易见的东西都会让更有经验的人更加突出

回答

3

Ajax在这里毫无意义,你所要做的就是请求一个将文件推送到浏览器的链接。尝试:

window.location.href = "export.php?filter=" + filter + "&maxrecords=" + maxrecords + "&type=" + type; 
+0

同意,除了maxrec来自用户输入,所以它需要encodeURI应用:) – Kato 2012-04-12 15:37:52

+0

工作像一个魅力,是卡在jQuery的心态。干杯。 – craighandley 2012-04-12 16:03:32

0

在我的一些项目中,我做了类似的工作,但完全不同:)。

在下拉列表中,我会打开新窗口,然后在那里执行karim79代码(例如身体负载)。 等下拉项

  1. 点击
  2. 适当的参数像在新窗口打开:在身体的onload事件
window.open ("newindow.html?filter=" + filter + "&maxrecords=" + maxrecords + "&type=" + type"); 
//this is not tested, but you got the point 
  1. 既可以执行:
window.location.href = "export.php?filter=" + filter + "&maxrecords=" + maxrecords + "&type=" + type"; 

或类似的东西。

相关问题