At the moment I'm passing data to node js server via javascript and the reason i must do this is because I'm using socket.io so I emit the data from the client.
There's a method on javascript to store data on a div and the data is invisible on the div $('#divID').data('name','value'); but still the user can see the data when i'm storing it and when I'm sending it. Is there a way I can store and emit the data via javascript the way that user can't change or see it?
It's a 16-digit user ID.
Javascript in essence is meant to be publicly viewable. Anybody with the knowledge of Javascript will be able to see everything that you are doing. So, you will have to continue to send it to the server before it can go to the database.
Related
so I will try to be as clear as possible on my question!
On my site I have a table with the latest reservations, it's a fetch request that retrieves the data in PHP in JSON format and Javascript that puts them in shape, it works very well. But now I would like to go one step further, and make an automatic system, which would only have the Javascript function to retrieve and format the data. But I would need to do this without having to do a setInterval() or wait for the user's click, somehow only when a row is added (which is not done by the admin but the system the detect), the array is reloaded. I don't know at all if it's possible or not, and that's why I'm asking here?
(I only work in Javascript with Jquery and with PHP, I don't know if I need another lib?)
Thanks in advance and have a nice day!
I think if you use websocket, you can get better system.
but, if you can't, I recommend you use setInterval() to check if the row added.
You can install websocket server with nodejs easily.
and you have to add send event from php to nodejs ( http ) when new row added in your PHP server.
and add javascript websocket client.
I have a form on my website that I want to ensure each client only submits once per year.
To do this, I would like to save the client's id # and the current year to a .txt file on my server when they submit the form.
When the form is submitted, I also need to check the current contents of that file to ensure their id has not already been recorded, and display a message if they have already submitted the form that year.
I believe I need to use PHP to do this, but I'm brand new to PHP and I'm also not very experienced with jQuery. Any assistance would be much appreciated!
Using a simple database would be much better, because it will be easier to retrieve the stored data later on. There are more than enough tutorials if youre not familiar with databases (use mysql database if you have few experience with databases).
If you use a database you can also store the submitted data from the form very easy.
As Dan already said, first learn PHP and database connects and querys and then jQuery (which you dont need for putting data from a form into a database, but with ajax its cooler (you dont even need jQuery for ajax, vanilla javascript can also do that for you) ;) ).
Just google everything, there are more than enough tutorials online.
If you don't want to use a database, probably the simplest option will be to rename the received file with clientId-currentYear when you put it on the server.
For example, when a user submits a file for client 12345, you will have to check if a file 12345-2018 already exist. If it doesn't exist, you can create it, if not, you send your message to the user.
This is going to be easier to manage than a text file or a database if your programming level is low.
I'm controlling a d3JS interface from another platform. The workflow: Data->Python to create JSON->d3JS to generate graphic->load the html page locally in a browser.
Is anyone aware of a way within this workflow to force a page reload when the JSON data is updated?
This is essentially a problem of how to push updates from the server to the client.
There are two approaches:
Fake it. You could use AJAX polling to periodically ask the server whether new data is available.
Do it for real. You could use WebSockets to push the data from the server to the client when an update occurs.
With the new data in hand, it should be simple to bind in D3 via the General Update Pattern. See http://bl.ocks.org/mbostock/3808218
If you must reload the page, you can also use either of these approaches to trigger it.
Is there any easy way to move data from localStorage or sessionStorage into a MySQL database with callbacks?
I'm guessing this would be done with AJAX, but I can't find a good how-to or guide for it. Basically, I'd like to send localStorage to the server, and alert the user as to whether or not the data was successfully stored by the server into MySQL.
It's been a while since I messed around with this, but localStorage is basically just an object, right? Which means that it could be sent as JSON? So you could construct an AJAX call to a PHP page, send the JSON, and then (after the PHP has messed with it and tried to insert it and echoed the result) alert the user as to what happened, right?
(Obviously, you could do this with any server-side language.)
Does any body know how to persist javascript changes on the server side.
For example if I added items to a drop down list client side, how can i persist them in order to read them on the server side.
By the way, Telerik control have this feature.
Your questions doesn't contains any details, so I can only give you a generic answer:
You have to post the new data back to the server, either by using AJAX (I'd suggest using jQuery) or by sumbitting the new data in some field (preferably hidden) with a regular html-form (can be done in JavaScript or by having the user click "submit").
You need to tell the server what the Javascript did using AJAX or a hidden field.