0
React js as frontend and php as backend
I saw couple of videos in YouTube about using react js as frontend and php as backend, do you think this approach will be successful?
6 Answers
+ 1
React is an open-source JavaScript library providing a view for data rendered as hyper text markup language. React, in case youâre not familiar with it, is a library for front-end web development. You use it to create components: little not-really-HTML tags that you can compose together to create your UI.So using it for front end is better than using it for server side , Php is one of the best server side language , So use pHp for back end
+ 1
mr.Ahmed for this exist tow possibility. First is in package.json must add example "proxy": "http://localhost:80" for use php, make folder one for react client and another for php. React app must have some like this
Brisanje(e){
fetch('http://localhost/fetchReact/server/prijem.php',{
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type':'application/json'
},
body: JSON.stringify({
content: this.state.name
}),
})
.then( res=> res.json())
.then( response => {
console.log(response);
alert(response.message);
});
}
for calling index.php file. And in index.php needed code
<?php
header('Accept: application/json');
header('Access-Control-Allow-Methods: POST,GET,PUT,DELETE,OPTIONS');
header("Access-Control-Allow-Headers: eToken,X-Requested-With,Content-Type");
header('Content-type: text/json; charset=utf-8; application/x-www-form-urlencoded');
header('Access-Control-Allow-Origin: *');
ini_set('xdebug.overload_var_dump', 0);
include 'funkcije.php';
$requestData = json_decode(file_get_contents('php://input'), true);
if(!isset($requestData)) {
$requestData = $_POST;
if(!isset($requestData) && count($requestData) == 0) {
response(null, "No request data.", true);
return;
}
}
if(!isset($requestData['requestName'])) {
response(null, "No requestName in request data.", true);
return;
}
switch ($requestData['requestName']) {
case RN_LOGIN:
$result = login($requestData['email'], $requestData['sifra']);
response($result);
break;
case "logOut":
logout();
break;
+ 1
next is in file function.php make funcitions for server action
+ 1
thanks very nice
0
āĻāϰāĻž āĻĢā§āϞā§āϰ āĻĒāĻžāĻĒāĻĄāĻŧāĻŋ> āĻāĻŋāĻā§ āĻāĻžāϞā§āĻŦāĻžāϏāĻž āĻā§āĻŦāύ āĻāĻžāĻā§ āϰāĻā§āĻā§āύ āĻāϰ⧠āĻĻā§āϝāĻŧ.., āĻāĻŋāĻā§ āĻāĻžāϞā§āĻŦāĻžāϏāĻž āĻā§āĻŦāύā§āϰ āϏāĻŦ āĻāĻžāϞā§āĻŦāĻžāϏāĻž āĻā§āĻĄāĻŧā§ āύā§āϝāĻŧ..| āĻāĻŋāĻā§ āϏā§āĻŦāĻĒā§āύ āĻĻā§ āĻ ā§āĻā§ āĻšāĻžāϏāĻŋ āĻĢā§āĻāĻžāϝāĻŧ..., āĻāϰ āĻāĻŋāĻā§ āϏā§āĻŦāĻĒā§āύ āĻĻā§ āĻā§āĻā§ āĻ
āĻļā§āϰ⧠āĻāĻĄāĻŧāĻžāϝāĻŧ...| āϏā§āĻŦāĻĒā§āύā§āϰ āĻŦāĻžāϏā§āϤāĻŦāϤāĻž āĻŦāĻšā§āĻĻā§āϰ...!!! āĻāĻŋāĻā§ āĻā§āϞ āĻā§āĻŦāύā§āϰ āϏāĻŦ āĻā§āϞ āĻā§āϞ⧠āĻļā§āϧ āϰāĻŋāϝāĻŧā§ āĻĻā§āϝāĻŧ..., āĻāϰ āĻāĻŋāĻā§ āĻā§āϞ āĻā§āĻŦāύ⧠āĻāϞāĻžāϰ āĻĒāĻĨāĻāĻžāĻā§ āύāώā§āĻ āĻāϰ⧠āĻĻā§āϝāĻŧ...|
0
no active avri body