doushen1026 2017-04-05 11:56 采纳率: 100%
浏览 47
已采纳

将数据发送到新的弹出窗口

trying to send data to a new window that doesn't originate from a form.

This is what I tried:

window.open('/path/to/file.php', 'bundle', 'height=700, width=500');
$.post('/path/to/file.php', {id: $(this).data('id')}, function(res)
{});

but var_dumping $_POST returns an empty array.

the data as you can see is being passed with $(this) (the trigger is an .on('click')) and I'm not a fan of the idea of having to create a hidden form - surely there must be a way to use $.post (or something else) to just post and open a new window - any ideas? Thanks :)

  • 写回答

2条回答 默认 最新

  • dor65412 2017-05-24 11:16
    关注

    Found an answer:

    $.post('path/to/post.php', {data: 4}, function(res)
    {
        var win = window.open('', 'UNIQUE_WINDOW1', 'width=1472, height=300');
        with(win.document)
        {
            open();
            write(res);
            close();
        }
    });
    

    this posts the data to post.php, opens the page using with and then writes the response to the window. No performance penalties either it seems. (note - refreshing these pages won't update, you need to trigger the $.post event to update the page)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大