A
A
Alexander Gorkin2018-09-25 16:27:53
AJAX
Alexander Gorkin, 2018-09-25 16:27:53

How to handle data received by Ajax?

There is a Json request that looks like this:
"
{"user":{"id":69279,"name":"\u0412\u0438\u043a\u0430","city":"\u041c\u043e\u0441\ u043a \ u0432 \ u0430 "," avatar ":" \ / storage \ / 31 \ / 33 \ /3133f88cbe33bcd01a6ba439d75ae9960daa9a994f235740849e7a4f4ee91257.jpg-50x50.jpg "," big_avatar ": " \ / storage \ / 31 \ / 33 \ / 3133f88cbe33bcd01a6ba439d75ae9960daa9a994f235740849e7a4f4ee91257. jpg-800x800.jpg","age":43,"video":"k87jc9u7"}}
"
With each new request, it generates a new user. The task is to display 6 users in the form of a gallery, and update their data every 5 seconds. I can't figure out how to do it.
HTML

<div class="index-page">
    <div class="container">
        <div class="third-row users-gallery">
            <div class="row">
                @foreach ($users as $k=>$user)
                <div  class="user-holder col-3 col-lg" data-num="<?=$k?>">
                    <div class="user" id="user">
                        <span id="name" class="img" style="background-image: url('{{Config::get('constants.image_host') . $user->big_avatar}}')" ></span>
                        {{--<span class="name"></span>--}}
                        <span class="lastname">{{Config::get('') . $user->name}}</span>
                    </div>
                </div>
                @endforeach
            </div>
        </div>
    </div>
</div>

Here is the js code:
function show(){
  	$.ajax({
  		url: '/random_user', 
  		type: 'GET', 
  		dataType: 'json', 
  		error: function(text){
  			alert('error');
  		},
  		success: function(json){ 
  			$('#user').html(json);
  			console.log(json);
  		}
  	});
  };

  $(document).ready(function(){
  	show();
  	setInterval(show,5000);
  });

I received the js data, but I can’t figure out how to properly scatter them in html. Help me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2018-09-25
@dimonchik2013

when more than one - in a loop

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question