我跟隨此帖子http://www.the-art-of-web.com/php/dataexport/併成功創建從DB導出到csv文件,基於用戶當前的搜索視圖。但是爲了防止在導出過程中碰到數據庫,所以我禁用了導出,除非視圖或用戶查詢中有更改。我面臨的問題是當用戶點擊導出文件保存爲確認對話框彈出,如果用戶改變主意,點擊取消。導出按鈕保持禁用狀態。用戶返回的唯一方法是更改查詢並再次返回。如何捕獲文件保存爲取消響應
我的問題是無論如何,我可以捕獲點擊迴應文件保存爲確認對話框。
感謝
的代碼非常相似http://www.the-art-of-web.com/php/dataexport/凡作爲視圖將與一羣來自定日期範圍內的客戶信息的網格。如果用戶喜歡他們選擇的視圖。他們會點擊導出按鈕。
示例代碼 export.php
function exportCSV(){
document.getElementById("exportCSV").src = "test1.php";
document.getElementById("exportBtn").disabled = true;
}
function performSearch(){
//perform search get result and display
//if resultset length > 0
document.getElementById("exportBtn").disabled = false;
}
網格顯示右這裏 <按鈕ID = 「搜索」 的onclick = 「performSearch()」>搜索
<按鈕ID = 「exportBtn」 的onclick =」 exportCSV() 「>導出
< IFRAME ID =」 exportCSV」風格= 「顯示:無」/>
test1.php
$數據=陣列(
陣列( 「姓名」=> 「瑪麗」, 「姓」=> 「約翰遜」, 「年齡」=> 25),
陣列( 「姓名」=> 「阿曼達」 ,「姓氏」=>「米勒」,「年齡」=> 18),
array(「firstname」=>「Patricia」,「lastname」=>「Williams」,「age」=> 7),
array(「firstname」=>「Michael」,「lastname」=>「Davis」, (「firstname」=>「Patrick」=> 43),
array(「firstname」=>「Sarah」,「lastname」=>「Miller」,「age」=> 24),
array ,「姓氏」=>「米勒」,「一個ge「=> 27)
);
#下載文件名 $ filename =「website_data.xls」;
header(「Content-Disposition:application/octet-stream; filename = \」$ filename \「」);
header(「Content-Type:application/vnd.ms-excel」);
$ flag = false;
的foreach($數據作爲$行){
如果(!$標誌){
#顯示字段/列名作爲第一行
回聲破滅( 「\ t」 的,array_keys($行))。 「\ n」 個;
$ flag = true;
}
array_walk($ row,'cleanData');
echo implode(「\ t」,array_values($ row))。「\ n」 個;
}
exit;
function cleanData(&$str)
{
$str = preg_replace("/\t/", "\\t", $str);
$str = preg_replace("/\r?\n/", "\\n", $str);
if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"';
}
請張貼一些代碼,也不需要在標題中有多個感嘆號 – Woot4Moo 2010-11-16 20:26:47
向我們顯示javascript – Galen 2010-11-16 20:26:50
該代碼與http://www.the-art-of-web.com/非常相似php/dataexport /這裏的視圖將會是一個網格,其中包含來自給定日期範圍的大量客戶信息。如果用戶喜歡他們選擇的視圖。他們會點擊導出按鈕。 – user332951 2010-11-16 21:31:27