How to display a specific value from an array in jQuery / getJSON?

Basically I get a JSON feed using jquery using:

$.getJSON("http://localhost/1.php?method=getAllUsers&jsoncallback=?")

I get the values ​​from the feed stored in an array named data

eg:.

x => 1
y => 3
z => 5

(obviously this is in json format)

after this script i have html and the table

<table><tr><td>y</td><td>value of y from the feed</td></tr></table>

Now, how can I get a specific value yin my table? Any help would be appreciated.

thank

+3
source share
3 answers

Have you tried something that didn't work? Because I would suggest that using json_object.ywill give you that value.

0
source

You need to use the DOM methods to find the corresponding element <td>and change its contents.

jQuery, id <td>:

<td id="foo"> ... </td>

script:

$('#foo').html(data.y);

(.. HTML- foo - data.y)

0

You can use the jQuery template plugin to compile your data using your template, which may be the best way to do this, see more information here

JQuery Template

0
source

Source: https://habr.com/ru/post/1787185/


All Articles