大家好,我有下面的代码,但当我点击生成的链接时,一个新页面打开,上面显示0。我做错了什么?
function list_reservation_to_csv() {
global $wpdb;
$table_name = $wpdb->prefix . \'prenotazione_eventi\';
$file = \'email_csv\'; // ?? not defined in original code
$results = $wpdb->get_results("SELECT * FROM $table_name",ARRAY_A);
if (empty($results)) {
return;
}
$csv_output = \'"\'.implode(\'";"\',array_keys($results[0])).\'";\'."\\n";;
foreach ($results as $row) {
$csv_output .= \'"\'.implode(\'";"\',$row).\'";\'."\\n";
}
$csv_output .= "\\n";
$filename = $file."_".date("Y-m-d_H-i",time());
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header( "Content-disposition: filename=".$filename.".csv");
print $csv_output;
exit;
}
add_action(\'wp_ajax_csv_pull\',\'list_reservation_to_csv\');
$ajax_url = admin_url(\'admin-ajax.php?action=csv_pull\');
<a href="<?php echo $ajax_url; ?>"><button>Scarica csv</button></a>