JavaScript AJAX Basics (retiring) Programming AJAX Stage 2 Challenge

balraj sarai
balraj sarai
6,303 Points

programming AJAX

Can you please check what the problem is with this code. I tried to do the rooms widget on my own. I do not get any errors, but the list comes undefined and in my employees list, instead of in the rooms list.

var xhr1 = new XMLHttpRequest();
xhr1.onreadystatechange = function () {
  if(xhr1.readyState === 4 && xhr1.status === 200) {
    var rooms = JSON.parse(xhr1.responseText);
    var statusHTML1 = '<ul class="bulleted">';
    for (var i=0; i<rooms.length; i += 1) {
      if (rooms[i].available === true) {
        statusHTML1 += '<li class="yes">';
      } else {
        statusHTML1 += '<li class="no">';
      statusHTML1 += rooms[i].room;
      statusHTML1 += '</li>';
    statusHTML += '</ul>';
    document.getElementById('roomList').innerHTML = statusHTML;
};'GET', '../data/rooms.json');

hi , i sugest you to add

var  your code here 

``javascript# and then close without hte phone sign adding three of that at the end of your code on next line

it will make easier and faster for peopel that will help you

David Mandel
David Mandel
31,174 Points

Two possible problems:

1) Class name for the unordered list has changed. It should now be:

'<ul class="rooms">'

2) Using the right class name for the list items. I think you need to change your if/else statement so that if true,

        statusHTML += '<li class="empty">';

And then if false the class name would be full.

Hope that helps!

1 Answer

balraj sarai
balraj sarai
6,303 Points

var statusHTML1 = '<ul class="rooms">';

i forgot to change the class name of this (above), and also forgot to change the variable names (below) to xhr1.'GET', '../data/rooms.json');

but thank you all for your replies.