GET vs POST in AJAX?

前端 未结 9 1376
北海茫月
北海茫月 2020-12-01 03:39

Why are there GET and POST requests in AJAX as it does not affect page URL anyway? What difference does it make by passing sensitive data over GET in AJAX as the data is not

相关标签:
9条回答
  • 2020-12-01 04:19

    Others have covered the main points (context/idempotency, and size), but i'll add another: encryption. If you are using SSL and want to encrypt your input args, you need to use POST.

    0 讨论(0)
  • 2020-12-01 04:20

    It's simply down to respecting the rules of the http protocol.

    Get - calls must be idempotent. This means that if you call it multiple times you will get the same result. It is not intended to change the underlying data. You might use this for a search box etc.

    Post - calls are NOT idempotent. It is allowed to make a change to the underlying data, so might be used in a create method. If you call it multiple times you will create multiple entries.

    0 讨论(0)
  • 2020-12-01 04:22

    Two primary reasons for having them:

    1. GET requests have some pretty restrictive limitations on size; POST are typically capable of containing much more information.

    2. The backend may be expecting GET or POST, depending on how it's designed. We need the flexibility of doing a GET if the backend expects one, or a POST if that's what it's expecting.

    0 讨论(0)
  • 2020-12-01 04:22

    Thanks.. I mainly use the GET method with Ajax and I haven't got any problems until now except the following:

    Internet Explorer (unlike Firefox and Google Chrome) cache GET calling if using the same GET values.

    So, using some interval with Ajax GET can show the same results unless you change URL with irrelevant random number usage for each Ajax GET.

    0 讨论(0)
  • 2020-12-01 04:23

    When we use the GET method in Ajax, only the content of the value of the field is sent, not the format in which the content is. For example, content in the text area is just added in the URL in case of the GET method (without a new line character). That is not the case in the POST method.

    0 讨论(0)
  • 2020-12-01 04:31

    You should use the proper HTTP verb according to what you require from your web service.


    When dealing with a Collection URI like: http://example.com/resources/

    GET: List the members of the collection, complete with their member URIs for further navigation. For example, list all the cars for sale.

    PUT: Meaning defined as "replace the entire collection with another collection".

    POST: Create a new entry in the collection where the ID is assigned automatically by the collection. The ID created is usually included as part of the data returned by this operation.

    DELETE: Meaning defined as "delete the entire collection".


    When dealing with a Member URI like: http://example.com/resources/7HOU57Y

    GET: Retrieve a representation of the addressed member of the collection expressed in an appropriate MIME type.

    PUT: Update the addressed member of the collection or create it with the specified ID.

    POST: Treats the addressed member as a collection in its own right and creates a new subordinate of it.

    DELETE: Delete the addressed member of the collection.


    Source: Wikipedia

    0 讨论(0)
提交回复
热议问题