Answer the question
In order to leave comments, you need to log in
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>
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);
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question