简体   繁体   中英

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. Can you help?

Assuming you're using POST data, and assuming that you're sending the data in JSON format the key would be:

 $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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM