我有这个代码:
<div id="messageDiv">
<form>
<textarea name="message" rows="10" cols="20" id="message"></textarea></textarea>
<br /><br />
<input type="submit" value="Send" onClick="return sendmail()">
<input type="reset" value="Reset" name='reset'>
</form>
</div>
然后我有我的 JS:
function sendmail()
{
var mail = document.getElementById('message').value;
window.location.href = "http://www.rainbowcode.net/apps_dev.php/profiles/mail?id="+mailid;
return false;
}
当我 alert(mail)
时,我得到了正确的值,但是当我通过 window.location.href 进入我的新页面时,我想访问该值...我的表单是一个“post “当我执行 print_r($_POST['message'])
时,我得到一个空数组。请帮忙?
最佳答案
通过使用 window.location.href
您只需更改要访问的链接(通过将页面刷新到所需页面,在您的情况下,该页面是从 URL 获取 id 的页面)。
如果要发布值,请使用 document.MyForm.submit();
编辑:
显然你必须添加一个正常的 <form>
标签,而不仅仅是一个空标签。
向其添加名称/ID,以便您可以使用 JS + 方法 post + 操作作为 URL 来引用它。
关于php - $_POST 数组为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6095156/