简体   繁体   English

我应该使用get还是post? 或两者?

[英]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文件中,我有一个用户文本输入字段和一个提交按钮,我想用此信息做几件事:

  1. Return a string from my server.js file to the same page 从我的server.js文件返回一个字符串到同一页面
  2. Increase a counter each time the button is pressed and output this value to a separate stats.js file 每次按下按钮时增加一个计数器,并将此值输出到单独的stats.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.

相关问题 如何在 app.use 中间件中同时使用 get 和 post - How to use get and post both in app.use middleware 我应该使用什么工具查看通过AJAX在客户端发生的GET和POST请求的详细信息? - What tool should I use to view details of GET and POST requests that are happening clientside via AJAX? 为什么我只得到一个 output 并请告诉我应该用什么来以最简单的方式解释这两个值 - why iam getting only one output and please tell what should i use to get both the values explain in simplest way 我应该同时使用 gtag.js 和 GTM 吗? - Should I use both gtag.js and GTM? 性能 - 我应该同时使用数组和对象作为巨大的列表吗? - Performance - should I use both Arrays and Objects for huge list? 我是否应该同时使用striptags()和htmlspecialchars()来防止XSS? - Should I use both striptags() and htmlspecialchars() to prevent XSS? 我应该只使用 IndexedDB 还是同时使用 IndexedDB 和 chrome.storage? - Should I use only IndexedDB or both IndexedDB and chrome.storage? 我应该使用 JSON 编码、JavaScript 编码还是两者都使用? - Should I use JSON econding, JavaScript encoding or both? 如何为GET和POST编写通用的XMLhttpRequest函数? - How can I write a common XMLhttpRequest function for both GET and POST? 如果我不使用 AXIOS 后处理程序应该如何<form action="“”" method="“POST”"></form> - How should an AXIOS post handler should look like if I don't use <form action=“” method=“POST”>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM