Forcing quot;Save Asquot; dialog via jQuery GET(强制“另存为通过 jQuery GET 对话框)
问题描述
我正在对下面的 test.php 文件代码调用 jQueryGET".
I'm calling a jQuery "GET" on the test.php file code below.
我试图让脚本在生成的 test.ini 文件上弹出另存为"对话框,以允许将其保存在本地.但是,虽然我可以很好地将结果回显到 jQuery,但我似乎无法弹出另存为"对话框.
I'm trying to get the script to pop a "Save As" dialog on the resulting test.ini file to allow it to be saved locally. However, although I can echo the result back to the jQuery fine, I can't seem to pop the "save as" dialog.
更新:感谢以下解决方案,我刚刚将 $.get 更改为 window.location.replace.
Update: Thanks to the solutions below, I just changed my $.get to a 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");
}
);
推荐答案
您无法获得显示另存为"对话框的 ajax 请求,但您可以做的是在页面中插入一个隐藏的 iframe 元素,然后将该 iframe 的源设置为您希望用户下载的 url.瞧,这是您的另存为.
You can't get an ajax request to show a "Save As" dialog, but what you CAN do is insert a hidden iframe element in the page, then set the source of that iframe to the url you want the user to download. Voila, there's your Save As.
这是一个复制和粘贴示例:
Here's a copy and paste example:
$('a#linky').click(function(){
var iframe = document.createElement("iframe");
iframe.src = "aHR0cDovL2V4YW1wbGUuY29tL2JyYW5kaW5nLnppcA==";
iframe.style.display = "none";
document.body.appendChild(iframe);
return false;
});
这篇关于强制“另存为"通过 jQuery GET 对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:强制“另存为"通过 jQuery GET 对话框


- PHP foreach() 与数组中的数组? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01