$ _POST数组为空

cha*_*cat 3 html javascript php

我有这个代码:

<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>
Run Code Online (Sandbox Code Playgroud)

然后我有我的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;
}
Run Code Online (Sandbox Code Playgroud)

当我alert(mail)得到正确的值,但当我通过window.location.href到达我的新页面时,我想访问该值...我的表单是一个"帖子",当我做一个print_r($_POST['message'])我得到一个空数组..请帮助?

Vad*_*klk 7

通过使用window.location.href你只需更改你要去的链接(通过刷新页面到所需的页面,在你的情况下是一个从URL获取id的页面).如果要发布值,请使用document.MyForm.submit();

编辑:显然你必须添加一个普通<form>标签,而不仅仅是一个空标签.添加一个名称/ ID,以便您可以使用JS +方法post + action作为URL来引用它.