Is javascript object with data of client save? - javascript

I instanciated an (javascript)object which should contain sensible data from our clients(read in via PHP from a database).
My question is now, if this data is save or should I let this run exclusively server-side?

Related

How to validate for data integrity between JS and PHP?

I am wondering about the right way of validating data on client and server side.
I have spreadsheet, made with JExcel addon, and I have to check if any user has changed headers. Spreadsheet data is generated using pivot function in database, so the column count and order would vary.
I locked all possibilities of headers editing by ordinary users, but if someone knows how to use console, it may be unlocked. The pivot is similar to the picture below:
The JExcel loads data from dynamic JSON generated by PHP script. I can calculate "checksum" for header order, but how to validate it when user will update spreadsheet? I have to validate if user sends spreadsheet based on the same pattern.
How to do it in best way?
EDIT:
I created process logic:
When the data is called by the user, php generates datahash and assigns it to the php session_id.
Session_id is coded into md5 as well as datahash and all is saved to mysql database.
The datahash is passed via http headers with ajax response (to deliver hash for the client-side verification)
After the data is sent back, server reads all hashes generated within current php session.
If any hash matches - data is valid. This solution is good, because I only need info if this data has been sent to user.
You can use some JWT to sign your data in the server-side.

How to store a json Object serverside and respond with it

I am trying to make a webpage and server where a user can enter in recipes and have them sent to (using JSON) the server and have the server store them in a file so that if the server is closed and reopened the user can request for something they've entered previously and can get it. I know how to send the JSON object both to the server and how to send the JSON object back to the client. I should note this can't use jquery.
What I need help with is how to store it in a file server side and get the contents from it later using a node.js server. They should all be stored in the same directory and I need to know how to get a list of the recipes in that directory. I've tried looking around but I can't seem to find the answer :(.
Example:
user makes a recipies
{ name:"cheese n waffles"
time:90,
ingredients:"cheese, eggs and waffles",
equipment:stove
};
Browser sends the JSON object to the server.
Client asks for a list of the recipes stored.
user asks for the recipe for spaghetti.
what I need help with:
server gets a list of the recipes it has stored
server takes the JSON object and stores it in /serverRootDir/recepiesStorage
server accesses /serverRootDir/recepiesStorage and gets the spaghetti recipe
You should be using a JSON based database such as MondoDB
It takes some learming however implementing with a text file will eventually become much more work and will function poorly
(Posted on behalf of the OP).
I have solved the problem. I will be using:
To read a file (access a recipe): fs.readFileSync() or fs.readFile().
To save a file (update a recipe): fs.writeFileSync() or fs.writeFile().
To get an array of files in a directory (retrieve the list of recipes): fs.readdirSync() or fs.readdir().

Node - Angular Passing POST data from Server to Angular client

I have a Node.js server with Angular on the client side. I'd like the following to happen.
User posts a large JSON to /postjson. The large JSON object is used in the controller to render some data visualization. I don't want to store the JSON in a database, it should disappear when the window closes. How do I pass this data to the controller?
A potential solution is to use a route /api/postjson and receive the JSON server side. But I don't want to store it. How do I then pass this object to the controller/service/provider whatever is required?

Request php generated json data via javascript and meanwhile log in php

Currently I have a working javascript/jquery file that makes a request to a php file to retrieve json data. This works great.
Some information is taken from the server and send back to the javascript/jquery.
So:
Request from js to exchange.php ==>
exchange.php access database and gets certain data
<=== response from exchange.php to jquery to send data to js
js uses data to make some changes to the website (changes phonenumber)
This has to be done as fast as possible. But after I have send the data to the js I want the same exchange.php log this data + some userdata to another database. For speed reasons I want to do this after the data is sent to the javascript. Is this possible?
Currently I just call the logging class after I echo'd json_encode(); But does it make a difference? Or will the json be send only after the whole php file has finished running?

Sending JSON data to a client? D3.js rendering JSON data

I have a website with a form (currently it's plain HTML but we're switching to JQuery). The flow is like this :
Take in the user's inputs --- 5 integers
Make a call to a web service via REST
Run some calculations server side... and generate a JSON object
??? Now I have my result JSON object, but how do I get it to the client? Persist it?
??? Does the URL need to be the exact location of the JSON file? That would mean 100's
??? of JSON files in my web server's DIR.
D3.js on the client side, waits for the data to be present (via AJAX?).
var data; // a global
d3.json("path/to/file.json", function(error, json) {
if (error) return console.warn(error);
data = json;
visualizeit();
});
Once data is present, render for the client, and remove the calculator from the screen.
I'm having a tough time here, because I notice all AJAX requests need a URL.. but then does that mean I need to give a unique URL to each resulting JSON object? Doesn't that mean I need to persist that object?
I'd just like to have d3.js render my JSON object but unclear what are my options for where to put it.
How do I post parameter on d3.json?
Typically, you will pass some parameters via a javascript object or
a query parameter.
Basically, something like...
data = {}
data.var1 =5;
data.var2 =10;
var my_request = d3.xhr(url)
my_request.post(JSON.stringify(data), function(error,received)){
};
Or
d3.json(url+"?"+"var1=5&var2=10",function(error,received)){
}
Obviously, these form parameters can be parsed on the server easily. After the values are parsed on sever, the server can generate the new JSON using the form parameters that have been parsed.
Make sure that if you are running the script from a local page (or a page that is not on the website) that the server has the ability to allow cross origin (or domain) requests.
If you want to persist the data across multiple calls, you will probably have to to embed the callbacks, or use global variables.

Categories

Resources