title: Ajax to load a local json file
body: <p>I have already checked every problem here about how to use ajax to load a local json file, but nothing is working with me:</p>
  
  <p>This is my javascript code to display a local json file:</p>
  
  <pre><code>  // rooms selection code
  
  
       document.querySelectorAll('.select-room').forEach(p =&gt; {
          p.onclick = () =&gt; {
            var newRoom = p.innerHTML;
            if (newRoom==room) {
              msg =`You are already in ${room} room.`;
              printSysMsg(msg);
            } else {
              leaveRoom(room);
              joinRoom(newRoom);
              room=newRoom;
              loadChat();
                    }
        }
      });
  
  function loadChat(room) {
    $.ajax({
      url: "chat.json",
      dataType: "json",
      method: "GET"
    }).done(function(data) {
      console.log(data.room);
    });
  }
  </code></pre>
  
  <p>This is the server side code in python, flask to write in json file:</p>
  
  <pre><code>@socketio.on("message")
  def message(data):
      msg = data["msg"].rstrip()
      username= data["username"]
      time_stamp = strftime('%b-%d %I:%M%p', localtime())
      room = data["room"]
      message = [time_stamp,msg,username]
  
      if room in Messages_by_Room.keys():
          if (len(Messages_by_Room[room])&lt;= 2):
              Messages_by_Room [room].append(message)
          else:
              Messages_by_Room[room].pop(0)
              Messages_by_Room[room].append(message)
      else:
          Messages_by_Room.update({room: message})
  
      with open('./chat.json', 'w') as f:
          json.dump(Messages_by_Room,f, indent=2)
  
      send({"msg": msg, "username": username,"time_stamp": time_stamp}, room= data['room'])
  </code></pre>
  
  <p>The json file is stored in the same place of the javascript file.</p>
  
  <p>The error keeps telling me "jquery-3.4.1.min.js:2 GET <a href="http://127.0.0.1:5000/chat.json" rel="nofollow noreferrer">http://127.0.0.1:5000/chat.json</a> 404 (NOT FOUND)"</p>
  
  <p>Can you help me to read a local json file by ajax or another way, please?</p>