简体   繁体   中英

Send variables to server using p5.js

I am hosting a personal website that uses p5.js. The problem is I need to send the variables to the server so that whenever I access the website it saves my data. Lets just call the variable that i want to save "test". Test's value is 3, and I want it to stay at 3 next time I access it. And I can change test's value to 5, but its value stays 0 when I refresh the page (int test = 0) Thanks for helping out!

You don't need to send variables to the server to do this. You could just use cookies. Googling something like "JavaScript cookies" will give you a ton of results. I personally use this library , but you can easily write your own code that saves and loads cookies (in fact, if you don't really understands how cookies work, this is a good way to learn!).

The only reason you'd need to send something to the server is if you needed the values to persists for a user between different computers. This would require a login of some kind (not to mention code running on a server), and is a lot more work than just using a cookie. But if you really need to go this route, googling something like "JavaScript post" or "JavaScript ajax" will return a bunch of promising results. Of course, what you do with that information on the server is an entire project in itself.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM