JavaScript AJAX Basics (retiring) Programming AJAX Parsing JSON Data

Pai Boony
PRO
Pai Boony
Pro Student 4,529 Points

console.log not working

I'm using local server on my computer Xampp. I can load XHR "XHR finished loading: GET "http://localhost/AJAX%20Basics/2_Programming%20AJAX/video4/data/employees.json". but the console.log did not show any json. Here is the code

var xhr = new XMLHttpRequest(); xhr.onreadystagechange = function(){ if(xhr.readyState ===4){ var employees = JSON.parse(xhr.responseText); console.log(typeof employees); } }; xhr.open('GET', 'data/employees.json'); xhr.send();

Please help...

3 Answers

Neil McPartlin
Neil McPartlin
14,636 Points

6 months on I know, but just for the record...

line 2: change ...stage... -> ...state...

var xhr = new XMLHttpRequest();
xhr.onreadystagechange = function(){ // edit this line to say xhr.onreadystatechange...
 if(xhr.readyState ===4){
 var employees = JSON.parse(xhr.responseText);
 console.log(typeof employees);
 }
 };
 xhr.open('GET', 'data/employees.json');
 xhr.send();
Ozgur Parlakkilic
Ozgur Parlakkilic
8,399 Points

you need to add link to your workspace take a snapshot of it, this doesnt give me enough detail

just create a new workspace.....and just do the same...