Sco*_*t B 2 php jquery get savefiledialog
我在下面的test.php文件代码中调用jQuery"GET".
我正在尝试让脚本在生成的test.ini文件上弹出"另存为"对话框,以允许它在本地保存.但是,虽然我可以将结果回显给jQuery,但我似乎无法弹出"另存为"对话框.
更新:感谢下面的解决方案,我刚刚将$ .get更改为window.location.replace.
$('#test').click(
function()
{
//$.get('<?php echo get_bloginfo('template_directory') ?>/test.php');
window.location.replace("<?php echo get_bloginfo('template_directory') ?>/test.php");
}
);
Run Code Online (Sandbox Code Playgroud)
您无法获得显示"另存为"对话框的ajax请求,但您可以执行的操作是在页面中插入隐藏的iframe元素,然后将该iframe的源设置为您希望用户下载的URL.瞧,有你的另存为.
这是一个复制和粘贴示例:
$('a#linky').click(function(){
var iframe = document.createElement("iframe");
iframe.src = 'http://example.com/branding.zip';
iframe.style.display = "none";
document.body.appendChild(iframe);
return false;
});
Run Code Online (Sandbox Code Playgroud)