简体   繁体   English

如何通过 fetch() 或 axios 从前端向 .php 文件(后端)发送请求,然后得到一些像 json 对象这样的响应

[英]How send request to .php file(backend) from front end via fetch() or axios, then get some response like json object

我是 php 新手,我想使用 .php 文件作为 api,所以当我通过 fetch 或 axios 或任何其他方式从前端调用该 .php 文件时,它将以 json 格式返回数据.

有很多“假”api 来进行测试,这里是一个https://jsonplaceholder.typicode.com/

I think this solves your question, is to pass php data to front我认为这解决了你的问题,就是将 php 数据传递到前面

I would change only the call to your path or php file我只会更改对您的路径或 php 文件的调用

Returning JSON from a PHP Script 从 PHP 脚本返回 JSON

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在我从后端发送的前端返回 json 响应? - How to get the json response back in the front end that I am sending from my backend? 以对象为参数的 Axios GET 请求(来自后端) - Axios GET request (from backend) with object as parameter 尝试将 JSON object 从前端表单输入发送到 Express 后端 - Trying to send JSON object from front-end Form-Input to Express backend 如何在控制台中显示来自 Axios GET 请求的完整 JSON 响应 - How to show full JSON response in console from Axios GET request 如何将 object 从前端重新发送到后端? - How do I res.send object to the backend from the front end? 如何安全地将数据从后端发送到前端 - How to send data from backend to front end securely GET 请求在前端反复失败,但在后端没有 - GET Request repeatedly failed on the front end but not on backend 如何从后端的Ruby获取JSON嵌套的对象作为JSON到前端的AJAX - How to get **nested** objects as JSON from Ruby on the backend to AJAX in the front-end 如何从python django后端到前端的AJAX获取对象的描述? - How to get description of object from python django backend to AJAX in front end? 使用Axios将Vue前端的pdf文件上传/下载到Spring Backend - Upload/Download pdf file from Vue front-end to Spring Backend using Axios
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM