How to fetch data from localhost using PHP and React JS | How to display json data in react js

preview_player
Показать описание
How to fetch data from localhost using PHP and React JS | How to make API using PHP and my sql | how to display json data in react js

use below command for installing and creating react app:
-- first install nodejs
-- npm install react --save
-- npm install react-dom --save
-- npx create-react-app my-app
-- cd my-app
-- npm start

PHP core:
/****Simply add this code in you .php file and call it when required****/
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_METHOD']))
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS");
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']))
header("Access-Control-Allow-Headers: {$_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']}");
}
/************************/
Music: "Royalty free music from Bensound"

Freelancing for your website, comment below or contact me

Subscribe and Comment below for source code

#devamitjha #API #reactjs #fetchAPI #PHP
Рекомендации по теме
Комментарии
Автор

Thanks a lot. friend, ,
Frankly, I was really worried about this code for a few days.

I am a web designer and learning React.
I need to show my superiors a feedback project with getting the data from the database already given.

I have no knowledge of php, node.js, create api, database etc.

on Youtube,
Almost every video has long and complex code with creating APIs from localhost databases .. and lots of bla bla bla ..

In your video ..
This is a very easy way for non developers to fetch data.

Thank you once again for this.
Please always make jugaad type, basic, different types of videos

nitinsaxena
Автор

If not for the music, this would be the perfect tutorial for this task.

Cosmin_TheMusicGuy
Автор

Very good to see such type of important video tutorial. Great

MdShahinurIslam-frpp
Автор

THANK YOU! I have been looking for a very long time how to combine php and react.

littlebee
Автор

Excelente brother, me hacia falta ese codigo del core, pase mucho tiempo buscando la solucion

pduran
Автор

Thank you very much for the explanation and example. You have helped me a lot!

ivrub
Автор

Hi Dev Admit Jha, thank you for the excellent explanation. Will the same connection process work if I'm connecting to a live database server, not localhost?

techtaley
Автор

hi bro .. your turtorial is awesome ... but can you please upload how to insert and update???

zerovirusdetect
Автор

please send me also CRUD operation bro I like this tutorial of you..

brianadlawan
Автор

Hey! Thanks you! My question is that how would I upload this to a web hosting site? There is usually a public_html, I just put everything in there? And how would I change my fetch path if I upload to a web hosting site?

leventestancz
Автор

agradecerte por los código del core amigo, sin ellos nunca hubiera podido hacer funcionar la api local.

KEVINGARCIA-kwhd
Автор

This is excellent, just i was searching for. Can you please upload core.php file?

mecanovovic
Автор

How about the CRUD operation, my friend, do you know how to do that in reactjs and php

markjunderbesario
visit shbcf.ru