Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Kasim Khan
4,925 PointsExplain GET and POST to me please
I am still confused on the GET and POST method, and when are you likely to use it in everyday web design?
Thanks
2 Answers
James Barnett
39,199 PointsFrom the Treehouse Blog article The Definitive Guide to GET vs POST
Both HTTP methods can achieve the same goals, but an incorrect choice between them can lead to unexpected and potentially harmful outcomes.
GET VS POST BASICS
- Use
GETfor safe actions andPOSTfor unsafe actions. - Use
POSTwhen dealing with sensitive data. - Use
POSTwhen dealing with long requests. - Use
GETin AJAX environments.
A few things to keep in mind when to using GET
-
GETrequests can be cached -
GETrequests can remain in the browser history -
GETrequests can be bookmarked -
GETrequests can be distributed & shared
source: http://blog.teamtreehouse.com/the-definitive-guide-to-get-vs-post
Chris Shaw
26,676 PointsHi Kasim,
The GET and POST keywords are HTTP verbs as they describe a mode of transport, the most common use for them is in HTML <form> elements where you define a method which can be GET or POST, the difference is that GET simply passes data via the websites URL while POST uses HTTP headers to send data using application/x-form-urlencoded which allows a backend language such as PHP to access data through an previously empty array called $_POST but I won't get into that.
Depending on what your site needs to do depends on whether you need to worry about them as generally you would only require them if you did have a form on your site or have an ajax request that's retrieving content from the server on the fly.
You can read more about the HTTP world over at MDN.