javascript - how to view json file data in view source code -


let suppose have json file

and can read file in script this

$(document).ready(function () {          $.ajax({              type: "get",              url: "package.html",              datatype: "json",              success: function (data) {                  var t = '';                    (var = 0; < data.yeardata.length; i++) {                         var mainstorytitle = data.yeardata[i].players;                      (var j = 0; j < mainstorytitle.length; j++) {                          var storytitle = mainstorytitle[j].name;                          var topstorycontent = mainstorytitle[j].description;                          var storyimage = mainstorytitle[j].image;                          t = t + '<div class="content">';                          t = t + '<article class="topcontent">';                          t = t + '<header class="top" id="top1"><h2>' + storytitle + '</h2></header>';                          t = t + '<header class="bottom">';                          t = t + '<h6><img src="' + storyimage + '" height=150 width=200>' + '</h6></header>';                          t = t + '<content class="hide" id="content_' + j + '"><p>' + topstorycontent + '</p></content>';                          t = t + '</article>';                          t = t + '</div>';                          }                   }                    $(".content").html(t);               },              error: function (e, ts, et) { alert(ts) }           })      }); 

and put script in html file. when run this, works problem when click on view source inside shows path of json instead of exact data. hope got problem , please revert me asap.thanx

instead of using alert, use console.log(ts) post json file console. there can around , see json file clicking down arrow.

console.log(data); shows as: > object {data: array[2], responsemessage: "", success: true}   console.log(json.stringify(data)); shows as: {"data":[{"controllerid":2,"description":"aeon power monitor","devtype":1,"id":1,"name":"power monitor"},{"controllerid":2,"description":"aeon power switch","devtype":2,"id":2,"name":"switch"}],"responsemessage":"","success":true}  

json view log


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -