Json help.
- Started
- Last post
- 11 Responses
- insomnie
Need to display amount in HTML.
- supersimple0
var info = eval(JSON CODE);
document.getElementById('contain...- that sucked.
info.balance.amount
supersimple - Using eval() indiscriminately is dangerous. Use JSON.parse() instead.chow
- that sucked.
- insomnie0
Can you use pastie?
- insomnie0
Perfect, how can I load that data every time though from the url?
- supersimple0
having absolutely no knowledge of what you are trying to do - normally, you use a server-side language (PHP) to get the JSON from a URL. Then, you put that in to your JS. Good use of AJAX.
- insomnie0
I am trying to get data from that url and display it on a page.
- ernexbcn0
You need to proxy the request since you are doing a crossdomain request. Create a middle script on your host that does the actual json request to the other host and returns that value to JS.
- insomnie0
how do you proxy the request ?
- ernexbcn0
Create a php file on your server, named as price.php for example, use this code http://pastie.org/2346169
In your javascript, just do this: http://pastie.org/2346183
Hope it helps.
- insomnie0
P.S. Found this script.
http://benalman.com/projects/php…
- 3030
I asume you want to use JavaScript and get info via AJAX
var info = {
"balance": {
"amount": "1.72",
"amount_formatted": "$1.72",
"balance_id": "28121",
"created_at": "2011-08-09T12:52:02-0700",
"message": "My balance is $1.72 as of Aug 9th at 3:52pm EDT (America/New_York)"
}
};document.write(info.balance.amou...