S
S
Semyon Kataparov2016-03-19 16:33:24
PHP
Semyon Kataparov, 2016-03-19 16:33:24

The console displays information in json format, how to get text from it and display it on the site?

The console displays information in json format, how to get a picture from it and display it on the site?
What is displayed in the console (for example):
{"id":20,"name":"Nikita"}
All this should be transferred to the page in the function. For example, what would be like this:
Name: Nikita
Number: 20.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Anton Ulanov, 2016-03-24
@truexizt1

As an example:

$(document).ready( function() {
  $.getJSON("/user", function(arr){
    $.each(arr.data, function(){
      $("#dt_basic").append("<tr><td>" + this['username'] + "</td><td>" + this['phoneNumber'] + "</td><td>" + this['company'] + "</td><td>" + this['city'] + "</td><td>" + this['activated'] + "</td>");
    });
  });
});

upon request, we get JSON containing users in the form of an array, parse it, and display it in a table with ID dt_basic

Q
quux, 2016-03-24
@quux

var asdf = {"id":20,"name":"Nikita"}
console.log("name:" asdf.name)

D
Dima Pavlov, 2016-03-24
@beerb0x

Using JSON.parse(), you can get a JS object from JSON, and then work with it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question