-1

I'm using Laravel 5.3.

Essentially, when a user clicks a button on the screen, I need to get data from the database (using AJAX), and then display that data on the screen.

However, I'm not sure if I should be using a GET or POST request? I've only ever used GET requests for routing when the user wants to get to a specific page, like a GET request for /index or /profile.

Which should I use?

  • 1
    And you don't think I've already done that? I'm still confused, which is why I'm asking here. –  Nov 25 '16 at 05:39
  • 2
    Possible duplicate of [When should I use GET or POST method? What's the difference between them?](http://stackoverflow.com/questions/504947/when-should-i-use-get-or-post-method-whats-the-difference-between-them) – Aniket Sahrawat Nov 25 '16 at 05:49
  • A `GET` request is often cacheable, whereas a `POST` request can hardly be, It means you can make absolute `URL`s using `GET` and not with `POST`. For eg: http://example.com/?page=hello+world&id=1 is a get request with parameters named `page` and `id`. – Aniket Sahrawat Nov 25 '16 at 05:49

4 Answers4

1

There is a difference between GET & POST method in Laravel

  • GET is used when we want to get some data from the server and we do not send any parameter in request. And the security threat is not a concern, like you are opening a page on browser

  • POST is used when we want to send some parameter to the server and based on that parameter some processing is done. In laravel it is mandatory to include CSRF token wit the request for security concern.

So choose as per your requirement.

Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
1

easy! Use GET when you're to getting data, and POST when you're posting data.

There are even more of these request methods (or verbs, if you like). For example a PUT request to edit data, DELETE request to delete data etc. However, these aren't supported in most browsers yet, but i know laravel has a clever workaround so you can use them anyway. check this links:

https://laravel.com/docs/5.3/routing

0

This is actually something of your own choosing. If the operation is a sensitive one you might consider using POST so that you can have protection over CROSS-SITE REQUEST FORGERY from attackers but if not so you can simply use GET

Ghost Worker
  • 640
  • 6
  • 17
0

If you only want save data in database(no return data) so you should use POST. And whenever you want to get data from database so you should use GET. Ex - If you want to insert a new user information in database so here you use GET method and if you want to edit existing user information and return updated information so you will use GET method.