[英]Should I use get or post? Or both?
I'm relatively new to get and post etc, so any help is welcome! 我是相对较新的获取和发布者,因此欢迎任何帮助!
In my App.js file, I have a user text input field and a submit button, and I'd like to do a couple things with this information: 在我的App.js文件中,我有一个用户文本输入字段和一个提交按钮,我想用此信息做几件事:
Am I on the right lines by thinking I should use a post to send the button click event back to server.js, and another post to return the string from server.js? 我是否认为我应该使用一个帖子将按钮单击事件发送回server.js,而使用另一个帖子从server.js返回字符串呢?
And the same for the second point? 第二点是一样的吗?
Ie In the button onClick function: 即在按钮的onClick功能中:
<form action = '/' method = ‘POST’>
And in the server.js, something like: 在server.js中,类似:
App.post('/', (req, res) {
// return string code here
}
I think I just need a bit of guidance on which files i should be doing methods :) any help appreciated! 我想我只需要对应该使用哪些文件的方法进行一些指导即可:)任何帮助,不胜感激!
<FORM>
actions should always be a POST
<FORM>
操作应始终为POST
As a general rule for other transfers - use GET
to 'request' data, and POST
to send/upload it. 作为其他传输的一般规则-使用GET
“请求”数据,然后使用POST
发送/上传数据。
Read section 4 of RFC 7230 . 阅读RFC 7230的第4节 。
Forget about the user interface for the moment. 暂时忘记用户界面。
You want to get some information from the server and record some statistics about it. 您想从服务器获取一些信息并记录有关它的一些统计信息。
The statistics are a side effect, they aren't the real purpose of the request, they are essentially just a standard access.log file. 统计信息是一个副作用,它们不是请求的真正目的,它们本质上只是一个标准的access.log文件。 This means that, despite the record of the request being made, you are making a safe request. 这意味着,尽管已记录了请求,但您仍在进行安全的请求。
So make one request, and make it a GET request. 因此,提出一个请求,并使其成为GET请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.