[英]How do I actually retrieve information server-side using PHP that a client-side JavaScript program sent to it with the fetch() function?
I'm trying to actually get the information at the server with PHP that was sent to it from the second parameter of the JavaScript fetch function.我正在尝试使用从 JavaScript 获取 function 的第二个参数发送给它的 PHP 在服务器上实际获取信息。 Can you help?
你能帮我吗?
Assuming you're using POST data, and assuming that you're sending the data in JSON format the key would be:假设您正在使用 POST 数据,并假设您正在以 JSON 格式发送数据,则密钥将是:
$input = json_decode(file_get_contents('php://input'), true);
if you add that to your php file the fetch is being sent to and var_dump
the resulting $input
you should be able to see how you can access the submitted data.如果您将其添加到 php 文件中,则 fetch 将被发送到
var_dump
生成的$input
,您应该能够看到如何访问提交的数据。
If not using json still take a look at the output of file_get_contents('php://input')
for a point in the right direction or update your question with more details of how you're using the fetch api.如果不使用 json 仍然查看
file_get_contents('php://input')
的 output 以获得正确的方向,或者使用有关如何使用获取 Z8A5DA52ED1264417A8AAZ77 的更多详细信息更新您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.