我正在尝试将数据发布到使用window.open方法打开的弹出窗口的新窗口(使用window.open(。我要做的是将选定的选项值传递给新打开的窗口,并使用$ _post加载数据。
这是我尝试的:
$(document).on('click', '.openForm', function()
{
var select = $(this).data('select'),
val = $('#'+ select).val();
$.post('/path/to/page.php', {id: val}, function(res)
{
window.open('/path/to/page.php');
});
});
和当前page.php的var_dump为$ _post,返回空。它还在新标签中打开页面而不是新窗口 - 我认为这与给出开放的Windows唯一名称有关?
我不确定如何获取它,因此$ .post可以在同一页面上发布并使用已发送的数据打开它 - 您知道的任何链接或解决方案都可以使用吗?
谢谢:(
这样修改您的脚本:
<script type="text/javascript">
$(document).on('click', '.openForm', function()
{
var select = $(this).data('select'),
val = $('#'+ select).val();
$.post('/path/to/page.php', {id: val}, function(res)
{
console.log(res);
var myWindow = window.open("", "MyWindow", "width=600,height=600");
myWindow.document.write(res);
//window.open('test_json.php',1,'width=600, height=600');
});
});
</script>
1($ _ post的var_dump返回空。因为您的请求$.post('/path/to/page.php')
和window.open('/path/to/page.php');
都会有所不同。第一个被视为帖子,将出现window.open('/path/to/page.php');
完成后,将是get
请求。
2(要打开窗口,而不是在新标签中打开窗口,您必须将其宽度和高度传递为window.open()
方法中的第3个参数。