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 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示