0

I have an external JSON file on my server that I want to display the objects from into an HTML document without using JQuery. I specifically just want to call the username object and display it on an "All Users" page for a simple homework project. I've had a difficult time finding ways to do this without JQuery. How could I go about doing this?

JSON Example:

{"name":"asfd","username":"awsf","email":"kean","age":"21","gender":"Male","submit":"Submit"},
{"name":"asdf","username":"asfd","email":"asdf@asdf","age":"21","gender":"Male","submit":"Submit"},
{"name":"null","username":"null","email":"null@gmail.com","age":"21","gender":"Male","submit":"Submit"},
{"name":"null","username":"null","email":"null@gmail.com","age":"21","gender":"Male","submit":"Submit"},
James A Mohler
  • 11,060
  • 15
  • 46
  • 72
  • Making an AJAX call without jQuery: https://stackoverflow.com/questions/8567114/how-to-make-an-ajax-call-without-jquery Parsing JSON: https://stackoverflow.com/questions/4935632/parse-json-in-javascript – Sverri M. Olsen Apr 07 '18 at 04:25

1 Answers1

0

If you have an array of json objects you can loop over it and call JSON.parse() on each. That will give you simple user object that you can access and place in your page his username.

for(var i=0; i<users.length; i++) {
    var user = JSON.parse(users[i]);
    // you can now access username for each user with user[i].username
    // place a username into new element in your page
}

Useful reference for making server call without jQuery : How to make an AJAX call without jQuery?

Mirko Acimovic
  • 508
  • 2
  • 9