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) Programming AJAX Parsing JSON Data

Krista Prenesti
Krista Prenesti
4,136 Points

Why does .responseText give OK in an alert but all of the data in the example? What is responseText?

Why does .responseText give OK in an alert but all of the data in the example? What is responseText?

3 Answers

The XMLHttpRequest.responseText property returns a DOMString that contains the response to the request as text. From https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseText

In other words, the XMLHttpRequest response property will return the response code, ie. 200 for OK or 404 for page not found, while the responseText property will return the text, ie OK or Page Not Found.

Emmanuel Plouvier
Emmanuel Plouvier
11,919 Points

Hi,

I'm not to totaly sure I understand your question but : responsText are a property of the obect was returned by an AJAX request.

I hope i can help you.

Krista Prenesti
Krista Prenesti
4,136 Points

Nevermind. I was confusing responseText with statusText. Doh!