PHP的$ _POST不喜欢我发布的内容

McK*_*yla 1 javascript php

众所周知,PHP有一个$_POST存储POST请求数据的变量.

我正在尝试将它与XHR一起使用..

xhr.send('hey=hello&hi=there'); 
Run Code Online (Sandbox Code Playgroud)

..但它不起作用..

echo $_POST['hey'] . ' ' . $_POST['hi']; # The page should say "hello there", but it doesn't.
Run Code Online (Sandbox Code Playgroud)

我是否错误地发送了数据?

我需要更改我的php.ini吗?

我如何让它工作?:(

hob*_*bbs 5

最有可能的问题是你没有发送带有Content-Typeof 的请求application/x-www-form-urlencoded,所以它被视为一个未知的数据块而不是一组URL编码的键/值对.

  • @tyler我在写出内容类型值时犯了一个错误.请再次使用`application/x-www-form-urlencoded`. (3认同)