0

I am trying to display contents of a json file which has 5 entries as the usual key value pairs, however I currently can only get the Name value to display as intended, the other values are registered literally as a direct return of the in put code. The getJSON method is to start after a button with id of #json is clicked. Its working but only displays the first item with the rest being output literally.
The code is below:

jQuery(document).ready(function($) {
  $(document).on('click', '#json', function(event) {
    event.preventDefault();
    var items;
    $.getJSON('somedata.json', function(data) {
      items = data;
      console.log(items['Name'], ['Phone'], ['Mphone'], ['Email'], ['Message']);
    });
  });
});

Tips welcome ! Thanks

Durga
  • 15,263
  • 2
  • 28
  • 52
minimallinux
  • 139
  • 2
  • 10

2 Answers2

1

You're not pulling the other values from items as with the first, do this instead:

console.log(items['Name'], items['Phone'], items['Mphone'], items['Email'], items['Message']);
UncleDave
  • 6,872
  • 1
  • 26
  • 44
0

You forgot to add items before ['Phone'], ['Mphone'] etc..

console.log(items['Name'],items['Phone'], etc..)
nounzor
  • 31
  • 2
  • Thanks, that got it displaying to console log, however I would also like to know how to display it in an alert using sweetalert, any tips welcome ! – minimallinux Oct 23 '17 at 23:26