Перейти к содержимому

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

Amit Jha

0:00 / 0:00

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

12 377 просмотров · 5 лет назад
Amit Jha
2,25 тыс. подписчиков
12 377 просмотров · 5 лет назад
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" You can donate at : paypal.me/devamitjha Freelancing for your website, comment below or contact me Subscribe and Comment below for source code #devamitjha #API #reactjs #fetchAPI #PHP