[英]Send variables to server using p5.js
I am hosting a personal website that uses p5.js. 我正在托管一个使用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.
测试的值是3,我希望下次访问它时该值保持在3。 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!
而且我可以将test的值更改为5,但刷新页面时它的值保持为0(int test = 0),谢谢您的帮助!
You don't need to send variables to the server to do this. 您无需将变量发送到服务器即可执行此操作。 You could just use cookies.
您可以只使用Cookie。 Googling something like "JavaScript cookies" will give you a ton of results.
谷歌搜索“ JavaScript cookie”之类的东西将为您带来大量结果。 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!).
我个人使用该库 ,但是您可以轻松编写自己的代码来保存和加载cookie(实际上,如果您不太了解cookie的工作原理,这是学习的好方法!)。
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.
这将需要某种形式的登录(更不用说在服务器上运行的代码了),并且比仅使用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.
但是,如果您真的需要走这条路,那么搜索诸如“ JavaScript post”或“ JavaScript ajax”之类的东西将返回很多有希望的结果。 Of course, what you do with that information on the server is an entire project in itself.
当然,您在服务器上处理这些信息本身就是一个整个项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.