Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
This is what my database looks like:
My question is how to I decrement the value of FIELD11 i.e. "4" in my realtime database in Firebase using javascript, everytime I click on DECREMENT Button on my html page it should decrement this value and get updated in realtime database. Thank You
I recommend you use a Firebase transaction.
When working with data that could be corrupted by concurrent modifications, such as incremental counters, you can use a transaction operation.
Example:
https://firebase.google.com/docs/database/web/read-and-write#save_data_as_transactions
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 days ago.
Improve this question
I am trying to retrieve the most recent message in a chat room and I am using React Native. I have stored all the chat messages in the chat state, however, my current code only returns the second to last message. Can anyone assist me in retrieving the latest message in the room?
const GetLastMessage = chat.length > 0 ? chat[chat.length - 1] : "New Message";
I think the reason for this is its retrieving second last msg is your component state is not updated yet and you are already getting that msg.Make sure a point where you are getting updated state and then retrieve a last msg.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
Since a year and a half I am trying to figure out how some websites update their content in real time without AJAX method.
Please see this example website: https://pro.btcturk.com/en/basic/exchange/BTC_TRY
That website is changing many texts within content in different timing.
It means that when the server is updated with new values in the database then the website is listening to database changes and then reflecting/delivering inside content without ajax calls.
Can someone give an example how to achieve such functionality possibly using Javascript or PHP normal hand-code appreciated?
Thank you
You can see the process here:
More information here: Websockets
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I have this saved in the database, but I can't find the correct line to console log it.
This is the last thing I tried and still not working:
var linesRef = database.ref("/lines");
console.log(
linesRef
.child("L1")
.val().eventattr
);
There are two ways to fetch data from firebase realtime database.
Either you can set a listener, which will automatically sync the data whenever there is a change in the database or you can do one time fetch
in your particular case (to fetch it one time)
you can do
const linesRef = firebase.database().ref("/lines");
linesRef.once("value")
.then(response => console.log(response.val()));
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Below is sample example for counter but i have to maintain the state after page is refree.For example i will increment the counter to 10 and next time when my page refreshes the page should start with 10 instead of 1.
Can anyhow guide me regarding this.
If you want to use cookies JS-cookie is really handy. Setting and retrieving cookie is really easy.
Use localStorage for that.
In your action handler do:
let counter = window.localStorage.getItem("counter");
window.localStorage.setItem("counter ", ++counter);
Then in your componentDidMount do:
let counter = window.localStorage.getItem("counter");
this.setState("counter", counter);
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
We are creating a website in which homework (with about 10 multiple choice questions) will be graded. Each question is on their own HTML page. How do we tally the overall grade of the homework, while keeping track of each multiple choice question? (Deduct .33 points twice if wrong, then tally that score to a total score for the homework)
You need to have some state to persist the answers. There are a number of options including:
save the answer to the server for each question
save the answer to localStorage
save the answer in a cookie
save the answer in the URL as a query parameter
If you prefer to stay client side, I suggest using localStorage. It is a key-value store with some limitations on size but it should be a good fit for your problem.
My approach would be to store the answer into localStorage for each question. On the final page, I would load all the answers and perform the calculation for points.
MDN: localStorage