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