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 trialDaniel Wagner
13,389 PointsCan GET be used to send data to a server?
In the "AJAX Basics" course the teacher states "The GET method is a simple way to send data to a web server." Is this correct? Up till that point I thought it was only to retrieve data from the server?
2 Answers
Kevin Korte
28,149 PointsMatt is correct. You can send data to the server via GET. It's obviously insecure, since the information is just hanging out there for everyone to see in the URL
Where GET request really shine is let's say you have an application that has many ways to filter by. Let's say I'm shopping for cars, and I filter by 2010 and newer, blue paint, SUV, and 4x4. All of these values could be in a get request so the server knows what filters to use. Because it's a get request, I can copy and paste URL as is to my wife, send it an an email, and when she clicks it, she would have the exact same filters set just how I had them, and thus see the exact same filtered results.
Matt F.
9,518 PointsThat is correct - you need to send the server some type of data in order for it to respond correctly.
For example, even if you just do a simple GET request to the route '/myRoute' it is still going to send the HTTP GET request's data to the server. This data will allow the server to determine whether the request is a GET, POST, PUT, etc, among other things.
You can also specify parameters in the URL of a GET request to use in server-side logic.
While it is possible to send JSON in the body of a GET request, it is not how GETs are expected to work.
Graeme Oxley
8,931 PointsGraeme Oxley
8,931 PointsGood answer. I actually work for one of the industry's leading automotive dealer website firms, and our inventory search pages work exactly like that. The site requests data from a JSON file containing all of the dealer's inventory information broken down into every characteristic for that vehicle and returned to the page in real-time as users check and uncheck the filter options. Affixing "?make=Ford" will filter out everything except Fords, and "?year=2011" will produce nothing but 2011 vehicles of any make or model.
Kevin Korte
28,149 PointsKevin Korte
28,149 PointsHey cool, thanks! It's a great way for a common problem.