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 AJAX Concepts A Simple AJAX Example

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
karan Badhwar
Web Development Techdegree Graduate 18,135 Points

multiple xmlhttprequest objects

Why do we need a new xmlhttprequest object for every new request we want to make cannot we just use the same object, as the teacher said we need to make a new object for every request?

And we just called the data, so does the data gets stored inside the xhr Object ?

Caleb Kemp
Caleb Kemp
12,754 Points

When your application tries to handle multiple requests at the same time, it tends to cause errors. Therefore, it is recommended to have your application handle only one request at a time.

If you had multiple requests and used only 1 object, hitting object.send would create multiple requests simultaneously, causing errors.

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
karan Badhwar
Web Development Techdegree Graduate 18,135 Points

Caleb Kemp, do you think so it can be because the Object itself holds the data so overwriting the data can cause problem, thats what I thought of when I wanted to move forward from this lesson

Caleb Kemp
Caleb Kemp
12,754 Points

xmlhttprequest objects use started a long time ago in 1999. At the time, the average user had very slow dial up internet, so making browsers and webpages as small as possible was a very big priority. Although potentially insignificant by today's standards, to save data, older browser's had a limit on the number of simultaneous connections allowed, IE6's limit (for example) was 2. Although modern websites could (or at least could have been designed to) handle as many requests as needed. It would cause a compatibility issue if that code was to run on older browsers.

So, yes, depending on the browser it seems like it could potentially create data overwrite or dropped requests. Actually I kind of had wondered about that same thing myself, great question :grinning:.