Jump to content

display array json data with ajax


tazeha

Recommended Posts

hello

 

json data is array

 

I want display mesghal values

 

p,d,....

 

{    "ati1": {        "p": "8,935,000",        "d": 0,        "dp": 0,        "dt": "",        "h": "8,935,000",        "l": "8,780,000",        "t": "۲۵ تیر",        "t-g": "16 July"    },    "ati2": {        "p": "8,665,000",        "d": 0,        "dp": 0,        "dt": "",        "h": "8,860,000",        "l": "8,665,000",        "t": "۲۵ تیر",        "t-g": "16 July"    },    "ati3": {        "p": "8,720,000",        "d": 0,        "dp": 0,        "dt": "",        "h": "8,905,000",        "l": "8,720,000",        "t": "۲۵ تیر",        "t-g": "16 July"    },    "ati4": {        "p": "8,840,000",        "d": 0,        "dp": 0,        "dt": "",        "h": "9,020,000",        "l": "8,825,000",        "t": "۲۵ تیر",        "t-g": "16 July"    },    "ons": {        "p": "1,135.30",        "d": "10.70",        "dp": 0.94,        "dt": "low",        "h": "1,146.50",        "l": "1,135.30",        "t": "۱۸:۳۰",        "t-g": "18:30"    },    "mesghal": {        "p": "3,889,000",        "d": 0,        "dp": 0,        "dt": "",        "h": "3,934,000",        "l": "3,883,000",        "t": "۲۵ تیر",        "t-g": "16 July"    }}
<script type='text/javascript'>            $(document).ready(function(){                                        $.getJSON('saipa.php', function(data) {                            console.log(data);                            $.each(data, function(key, val) {                                    $('ul').append('<li id="shoker">' + val.p + ' ' + val.h + ' ' + val.t + ' ' + val.l + '</li>');                            });                    });            });            </script>

but can't display

 

pleas help

 

Link to comment
Share on other sites

I write this but diplay undefined

 

 

 
 $(document).ready(function(){                                        $.getJSON('js.json', function(data) {                                                        $.each(data.mesghal, function() {                                    $("ul").append("<li>Price:" + this['p'] +"</li><li>Date:" + this['p'] +"</li>");                            });                    });            });

results:

  • Price:undefined
  • Date:undefined
  • Price:undefined

Edited by tazeha
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...