PREFACE: I’m new to JavaScript and working through some tutorials, and I’m stuck here!
I’m running the following locally on WAMP with PHP 5.3.13 installed. I’ve received no errors in the console, but for some reason nothing is displayed!
Anyone have any idea why?
Minimized JSON:
{"channel":{"title":"RSS Sample","description":"A sample RSS Feed","link":"http://www.website.com","copyright":"Copyright 2012"}}
JavaScript:
var xhr = new XMLHttpRequest();
xhr.open("GET", "rss.json", true);
xhr.onreadystatechange = function() {
if (xhr.readystate === 4) {
var status = xhr.status;
if ((status >= 200 && status < 300) || status === 304) {
var rss = JSON.parse(xhr.responseText);
alert(rss.channel.description);
} else {
alert("Request unsuccessful");
}
}
};
xhr.send(null);
Any help would be greatly appreciated! 🙂
The correct property name is
readyState(capital “S”).