GET vs. POST ajax requests: When and how to use either?

后端 未结 4 588
野的像风
野的像风 2020-12-15 05:01

What are the strengths of GET over POST and vice versa when creating an ajax request? How do I know which I should use at any given time? Is it a security-minded decision?

4条回答
  •  情话喂你
    2020-12-15 05:21

    You should use GET and POST requests in AJAX calls just as you would use GET and POST requests in normal calls. Basic rule of thumb:

    Will the request modify anything in your Model?

    • YES: The request will modify (add/update/delete) data from your data store, or in some other way change the state of the server (cause creation of a file, for example). Use POST.
    • NO: The request will not affect the state of anything (database, file system, sessions, ...) on the server, but merely retrieve information. Use GET.

提交回复
热议问题