简体   繁体   English

如何使用 PHP 实际检索服务器端信息,客户端 JavaScript 程序使用 fetch() function 发送给它?

[英]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.

相关问题 mongodb服务器端javascript实际上是客户端吗? - mongodb server-side javascript is client-side actually? 如何通过客户端javascript函数触发服务器端程序(shell脚本)的执行? - How to trigger execution of a server-side program (shell script) via a client-side javascript function? 如何将服务器端ASP XmlHttpRequest代码转换为客户端JavaScript? - How do I convert my server-side ASP XmlHttpRequest code to client-side JavaScript? 如何使用客户端 JavaScript 调用服务器端 NodeJS 函数 - How to call a server-side NodeJS function using client-side JavaScript 将客户端JavaScript变量传递给服务器端php - Pass client-side javascript variable to server-side php 正则表达式:检入PHP(服务器端)或Javascript(客户端) - Regex : Check in PHP (Server-side) or Javascript(client-side) 服务器端和客户端JavaScript - Server-side and client-side JavaScript 我需要在javascript /服务器端和客户端冲突中使用php变量 - I need to use php variables in javascript/ server-side and client-side conflict 使用 express 和 mongoose,如何使用 POST 路由将多个 ID 的数组从客户端发送到服务器端? - Using express and mongoose, how do I send an array of multiple IDs from the client-side to server-side using a POST route? 如何使用 JavaScript 正确编码服务器端和客户端之间的交换数据? - How to correctly code an interchange data between server-side and client-side using JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM