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!

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) jQuery and AJAX The jQuery AJAX Method

Hi could someone explain why in some examples online, for $.ajax() method one of the key-value pairs

is data: i ran my code for the project using this ajax() method. My question is what are we using the data (as one of the key-value pairs) for.


2 Answers

As you can see from the jQuery documentation for Ajax, "data" is one of many parameters that can be passed into the $.ajax() function. Here's the official description of the data parameter:


Type: PlainObject or String or Array

Data to be sent to the server. It is converted to a query string, if not already a string. It's appended to the url for GET-requests. See processData option to prevent this automatic processing. Object must be Key/Value pairs. If value is an Array, jQuery serializes multiple values with same key based on the value of the traditional setting (described below).

It's really good to get in the habit of checking a language (like jQuery)'s website for documentation in order to understand what people are doing when they write it. I've been writing in jQuery for years now and still visit their site regularly to check stuff like parameters, syntax, etc. Hope this helps a bit!

Ya thanks for your time... for new people like me even reading the documentation is daunting sometimes. some areas are pretty straight forward to follow while some are tough. Hope it gets easier with practice.