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

JavaScript AJAX Basics (retiring) AJAX and APIs Making the AJAX Request

Alex Robertson-Brown
PLUS
Alex Robertson-Brown
Courses Plus Student 8,956 Points

How does an object sent as data in a get request?

This might be a bit of a stupid question but I'm a bit lost on this point.

I know that you can add data to a request by including it in the url as a query string, but how does an object get sent? Does this get converted into a query string as well or is it sent in another way?

I've completely forgotten if this has already been explained in the videos, but I had a little look back & couldn't find the reference.

1 Answer

Aaron Graham
Aaron Graham
18,033 Points

You can serialize objects into strings and send them in the query string using an HTTP GET, as you alluded to. However, depending on what you are doing, it might be better to send it using an HTTP POST. Either of these methods are able to send objects but you should try and use HTTP verbs for their appropriate purposes.

Edit: I found this video that might help on the differences between GET and POST. http://teamtreehouse.com/library/ajax-basics/ajax-concepts/get-and-post