Answer the question
In order to leave comments, you need to log in
How to get data from json using jquery?
data.json:
{ 'new':'asdsa',
'list':[{
'name':'first',
'rating':'50%',
'story':'Once upon a time'
},
{
' name':'second',
'rating':'65%',
'story':'New chapter'
}]
}
Script:
<script type="text/javascript" src="jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$.getJSON('data.json', function(data){
alert('asdas');
alert(data.list[1].name);
});
</script>
Answer the question
In order to leave comments, you need to log in
Learn how to code for the fastest response!
JSON
{
"new":"asdsa",
"list":
[
{
"name":"first",
"rating":"50%",
"story":"Once upon a time"
},
{
"name":"second",
"rating":"65%",
"story":"New chapter"
}
]
}
$.getJSON('data.json', function(data){
console.log(data);
});
If you try to make such a request without using a web server (by opening the page as a file at "file:///...", locally) then the request will fail. Are you using a web server?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question