如何使用 jQuery/AJAX 将表单数据发布到新窗口?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8919019/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to post form data to a new window using jQuery/AJAX?
提问by Michael
One of the pages in my application has a set of links that when clicked, posts form data based on the TableTools jQuery plugin. I'd like this new page to open up in a new window. Any ideas on the best way to do this? I'd rather not change all of my action links over to individual forms and use target="_blank"
. I've tried calling a new window to open on success, and posting writing the data to this page, but that hasn't been working. Please help!
我的应用程序中的一个页面有一组链接,单击这些链接时,会根据 TableTools jQuery 插件发布表单数据。我希望在新窗口中打开这个新页面。关于做到这一点的最佳方法的任何想法?我宁愿不将所有操作链接更改为单个表单并使用target="_blank"
. 我试过调用一个新窗口在成功时打开,并将数据写入此页面,但这没有用。请帮忙!
HTML:
HTML:
<div id="action">
Download
</div>
Javascript:
Javascript:
$('#action').click( function () {
var userData = oTable.fnGetColumnData(0);
$.ajax({
type: "POST",
url: "../download.php",
data: "user_list=" + userData,
dataType: "json",
success: function(data){
var win = window.open();
win.document.write(data);
}
})
})
采纳答案by Michael
Found the answer:
找到答案:
jQuery.ajax success callback function not executed
When I took out the dataType: "json"
, it worked!
当我取出时dataType: "json"
,它起作用了!