J
J
justfro2019-12-24 19:16:32
React
justfro, 2019-12-24 19:16:32

How are requests made in React for a php file?

In general, there is absolutely no picture in front of your eyes how React implements this. There is a lot of information on the Internet, but
I generally have the dumbest task. Get info from a php file and not from https://......ru '
and how to prepare the right answer for such a request?
I understand that the topic is simple to business, but I really killed two days and did not understand anything at all.
On all sites the same thing ..... But I'm not catching up.

fetch('https://jsonplaceholder.typicode.com/todos/1')
  .then(response => response.json())
  .then(json => console.log(json))

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
gian_tiaga, 2019-12-24
@gian_tiaga

Your php file should give something to some address. To do this, as written above, you need PHP to work in conjunction with the server.

A
Abr_ya, 2019-12-24
@Abr_ya

What are you doing in your PHP? Are you submitting data in JSON format?
It seems to me that this is the simplest and most common way to organize an API.
Given that you almost didn’t give any information, I can imagine the following simple scheme:
1) PHP gives JSON,
2) React receives it and works with it further.
Any difficulties in implementing this scheme?
Or do you have a different approach?

R
Robur, 2019-12-25
@Robur

How are requests made in React for a php file?

Just like not in React - you already have the code, it will do
no way.
You can at best get info from localhost/myfile.php.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question