簡體   English   中英

使用jQuery加載頁面但不加載到容器div中

[英]Loading a page but not into a container div using jQuery

我有一個下拉菜單,我從中選擇一個文件類型,然后我希望它在一個生成文件的頁面上觸發,具體取決於所選內容並強制使用php中的header下載它。 這是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();
});

我目前正在強制進行測試,但它似乎並沒有達到預期的效果。 使用下面的數據處理文件時, export.php?filter='import'&maxrecords=15&type='xls'會強制下載。 只是不使用jQuery方法。 有什么明顯的東西對於更有經驗的人來說更突出?

Ajax在這里毫無意義,您所做的就是請求一個將文件推送到瀏覽器的鏈接。 嘗試:

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

在我的一些項目中,我正在做類似但完全不同的事情:)。

在下拉列表中單擊我將打開新窗口並執行karim79代碼(例如在體載上)。 所以

  1. 點擊下拉項目
  2. 用適當的參數打開新窗口,例如:
    window.open ("newindow.html?filter=" + filter + "&maxrecords=" + maxrecords + "&type=" +  type"); 
//this is not tested, but you got the point
  1. 在body的onload事件上執行:
window.location.href = "export.php?filter=" + filter + "&maxrecords=" + maxrecords + "&type=" + type";

或類似的東西。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM