<html>
<body>
<div id="output">hi</div>
</body>
<script>
var link="http://mywp.com/cilacap/api/get_posts/";
var jcontent= JSON.parse(link);
var output=document.getElementById('output');
output.innerHTML=jcontent.id' ';
</script>
</html>
It only shows “hi”.
Can someone tell me how to show JSON items such as “id” and “postDate”
with looping but without PHP scripting?
Thanks
Few syntactical errors, below is the right one.
JSON Data(var link)
, was not parsable.JSON Data(var link)
, didnt contained any attribute calledid
.String concatenation in last line(
output.innerHTML
), was wrong.Try removing the quotes from:
and change it to:
Providing that the link is valid it should work now.
You can also write:
and check if the console displays the value, or any errors that have occurred.
That url is a string, not json.
Use Ajax to get the data ( using jquery)
Then, extract the data;
Is for the value. You get the key like this:
ES7
ES6
ES5 (Most likely your case)
Use
function
instead ofarrow functions
for es5:Access the value:
Ps
If you want to use the es7 or es6 method, have a look at babeljs