You guys have done an absolute awesome job by creating Fuse and how easy it is to use with common procedures one want in an app, so therefore I have to thank you! However, I find it unbelievably frustrating when it comes to communication with my MySQL server through PHP scripts using JavaScript’s fetch() in Fuse. I can say I have experience with using PHP scripts on the server to receive and send back data with POST and JSON (C#) but this is just nothing like that. I have tried sooo many different combinations now the whole evening off of your Forums and by investigating JavaScript API but no luck so far and it’s starting to get really frustrating. I have managed to establish communication with my .php files on the server (i.e. just echoing random stuff and receive them in Fuse) but I have no idea how either send POST data or receive them in PHP with fetch() in JS… Could anyone please help me?
My .js file:
var Observable = require('FuseJS/Observable');
var Email = Observable();
var Password = Observable();
var fullname = Observable("7t978y9");
function logIn() {
var status = 0;
var response_ok = false;
var requestObject = {email: Email.value, password: Password.value};
console.log(requestObject);
fetch('http://www.myserver.com/sql/json/get_user.php', {
method: 'POST',
headers: { "Content-type": "application/x-www-form-urlencoded"},
body: JSON.stringify(requestObject)
}).then(function(response) {
status = response.status; // Get the HTTP status code
response_ok = response.ok; // Is response.status in the 200-range?
return response.json(); // This returns a promise
console.log("1st then");
}).then(function(responseObject) {
fullname.value = responseObject;
console.log("2nd then");
console.log(fullname.value);
}).catch(function(err) {
console.log("Fetch error: " + err);
});
}
module.exports = {
Email: Email,
Password: Password,
fullname: fullname,
logIn: logIn
};
My .php file:
<?php
require_once "../app_config.php";
$email = $_POST["email"];
$password = md5($_POST["password"]);
if (!$db) {
echo "No Connection";
}
else
{
$query = "select * from users where email = '$email' and password = '$password'";
$get_user = $db->query($query);
foreach ($get_user as $user) {
echo json_encode($user);
}
}
I’m desperate…