如何使用javascript在POST方法中发送数据 [英] how to send data in POST method using javascript

查看:80
本文介绍了如何使用javascript在POST方法中发送数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在javascript normaly中,页面重定向可以按照以下参数进行。

In javascript normaly page redirection can be done as follow with a parameter.

window.location = "add-new-cos.jsp?id="+id;

但是这个id值会在GET方法中发送到下一页。但我想用POST方法发送它。
有没有办法用javascript ....?

but this id value is send to the next page with in the GET method. but i want to send it with the POST method. is there any way to do it with javascript....?

推荐答案

不像 window.location 重定向但很容易:)

Not as easy as the window.location redirect but easy enough :)

var form = document.createElement("form");
    input = document.createElement("input");

form.action = "add-new-cos.jsp";
form.method = "post"

input.type = "hidden";
input.name = "id";
input.value = id;
form.appendChild(input);

document.body.appendChild(form);
form.submit();

这篇关于如何使用javascript在POST方法中发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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