2017-04-27 136 views
0

我试图从用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文件有$ _ POST返回空一的var_dump。它也在一个新的选项卡而不是一个新的窗口中打开页面 - 我认为这是为了打开窗口的唯一名称?

我不确定如何得到它,所以$ .post可以发布到同一页面并使用发送的数据打开它 - 您知道的任何链接或解决方案都可以工作吗?

谢谢:)

回答

1

修改你的脚本是这样的:

<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个参数传递。

+0

谢谢,这工作非常好! – ThisGuyHasTwoThumbs