获得与邮政阿贾克斯 [英] GET vs POST in Ajax
问题描述
在获取和发表的阿贾克斯要求?
我不明白这两者之间有什么区别,只是当我使用 GET ,参数发送URL,这对我来说真的不作出任何区别,因为所有的请求都做对的背景和用户不会发现任何区别。
I don't see any difference between those two, except that when I use GET, the parameters are send in URL, which for me don't really make any difference, since all requests are made on background and user doesn't find any difference.
编辑: 什么是 PUT 和删除用的呢?方法
edit: What are PUT and DELETE methods used for?
推荐答案
GET是专为从服务器获取数据。 POST(和鲜为人知的朋友PUT和DELETE)是专为修改服务器上的数据。
GET is designed for getting data from the server. POST (and lesser-known friends PUT and DELETE) are designed for modifying data on the server.
一个GET请求不应该导致数据从应用程序中删除。如果你有一个链接,您可以点击一个GET删除的数据,那么谷歌蜘蛛你的网站可能会点击你所有的删除链接。
A GET request should never cause data to be removed from an application. If you have a link you can click on with a GET to remove data, then Google spidering your site could click on all your "Delete" links.
的规范答案可以发现这里,它引用的是HTML 2.0规范:
The canonical answer can be found here, which quotes the HTML 2.0 spec:
如果表单的处理是幂等(即它没有持久 上的状态的显着影响 世界),则形式方法应该 得到。许多数据库的搜索没有 可见的副作用,使理想 查询表单应用程序。
If the processing of a form is idempotent (i.e. it has no lasting observable effect on the state of the world), then the form method should be GET. Many database searches have no visible side-effects and make ideal applications of query forms.
如果用表格的处理相关联的服务有副作用 (例如,变形例的 数据库或预订到 服务),该方法应该是POST
If the service associated with the processing of a form has side effects (for example, modification of a database or subscription to a service), the method should be POST.
在你的AJAX调用,你需要使用什么方法,你的服务器支持。你应该总是设计您的服务器,以便修改数据的操作由POST称为/ PUT / DELETE。其他意见有联系的休息,这通常映射C / R / U / D为POST或PUT / GET / PUT / DELETE。
In your AJAX call, you need to use whatever method your server supports. You should always design your server so that operations that modify data are called by POST/PUT/DELETE. Other comments have links to REST, which generally maps C/R/U/D to POST or PUT/GET/PUT/DELETE.
这篇关于获得与邮政阿贾克斯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!