我需要使用一个不依赖表单的按钮,如何让它向浏览器发送POST数据?
我正在使用:
<button style="height: 100px; width: 300px" onClick="parent.location='form1.php'" >Fill survey</button>
我需要使用一个不依赖表单的按钮,如何让它向浏览器发送POST数据?
我正在使用:
<button style="height: 100px; width: 300px" onClick="parent.location='form1.php'" >Fill survey</button>
你需要使用JavaScript创建一个表单,然后提交它。看看这段代码
HTML
<button type="button" onclick="proceed();">do</button>
这段 JavaScript 代码
function proceed () {
var form = document.createElement('form');
form.setAttribute('method', 'post');
form.setAttribute('action', 'http://google.com');
form.style.display = 'hidden';
document.body.appendChild(form)
form.submit();
}