How to display a specific value from the array in Jquery / getJSON?
Basically I am getting a JSON feed using jquery using:
$.getJSON("http://localhost/1.php?method=getAllUsers&jsoncallback=?")
I get the values successfully from t开发者_如何学Che feed stored in an array called data
eg.:
x => 1
y => 3
z => 5
(obviously this is in the json format)
after this script i have the html, and a table
<table><tr><td>y</td><td>value of y from the feed</td></tr></table>
now how can i get the specific value of y
into my table? any help would be apreciated.
Thanks
Have you tried something that didn't work? Because I would imagine that using json_object.y
would give you that value.
You need to use DOM methods to find the appropriate <td>
element and change its content.
As you're already using jQuery the simplest thing would be to put an id
on that <td>
:
<td id="foo"> ... </td>
and then use this in your script:
$('#foo').html(data.y);
(i.e. set the inner HTML content of the element with ID foo
to data.y
)
You can use jQuery template plugin to compile your data with your template, that may be the best way to do this, see more info here
JQuery Template
精彩评论