我跟随此帖子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