Javascript window.open 使用 POST 传递值 [英] Javascript window.open pass values using POST

查看:36
本文介绍了Javascript window.open 使用 POST 传递值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 javascript 函数,它使用 window.open 调用另一个页面并返回结果.

I have a javascript function that uses window.open to call another page and returning the result.

这是我的代码部分:

var windowFeatures = "status=0, toolbar=0, location=0, menubar=0, directories=0, resizable=1, scrollbars=1";
window.open ('http://www.example.com/index.php?p=view.map&coords=' + encodeURIComponent(coords), 'JobWindow', windowFeatures);

我现在的问题是我传递了太多数据供 GET 处理,我需要使用 POST 方法传递它.

My problem now is that I am passing too much data for the GET to handle and I need to pass it using the POST method.

如何将上面的代码转换为使用 POST 方法打开页面而不在整个页面上实现表单(页面列出了 100 个订单和供应商列表 - 我正在尝试映射供应商)

How can I convert the code above to open the page using the POST method without implement forms all over the page (the page lists 100's of orders with a list of suppliers - I am trying to map the suppliers)

推荐答案

我使用了上述的变体,但我没有打印 html,而是构建了一个表单并将其提交给 3rd 方 url:

I used a variation of the above but instead of printing html I built a form and submitted it to the 3rd party url:

    var mapForm = document.createElement("form");
    mapForm.target = "Map";
    mapForm.method = "POST"; // or "post" if appropriate
    mapForm.action = "http://www.url.com/map.php";

    var mapInput = document.createElement("input");
    mapInput.type = "text";
    mapInput.name = "addrs";
    mapInput.value = data;
    mapForm.appendChild(mapInput);

    document.body.appendChild(mapForm);

    map = window.open("", "Map", "status=0,title=0,height=600,width=800,scrollbars=1");

if (map) {
    mapForm.submit();
} else {
    alert('You must allow popups for this map to work.');
}

这篇关于Javascript window.open 使用 POST 传递值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆