0
I have a webservice in json that returns me the last people who passed in a certain location.
That said I did the following:
I only ask for the api always the information of the last person to pass on site.
I created on my in page
setInterval
of 1s to read this api and make aprepend
with the information of this json on the screen within a div.
Done this I noticed that there is a problem. When several people pass in less than 1s I lose or better I skip the display of some people on the screen.
I set by default the api to always return the last 9 people to me so I need to compare the box ids that are already on the screen with the ids that come from json and know which Ids don’t have on the screen so I can include these people in the prepend. Could someone assist me in this question of knowing which ids exist in an array 1 that do not exist in array 2 ?
I made a code according to the help below but it is returning
setInterval(function() {
var api = [],tela = [];
$(".cardface").each(function(){
tela.push($(this).attr('idimg'));
});
$.getJSON('<?php url(); ?>/rtffeed', function(data) {
$.each(data, function(key,val){
api.push(val.id_imagens);
});
});
var adicionar = $(api).not(tela).get();
console.log(adicionar);
}, 1000);
whereas if I do
console.log(tela);
he returns
{317,318}
and I do
console.log(api);
he returns {322,321,319,318,317,316,315,314,313}
then the add should be {322,321,319,316,315,314,313}
but he’s coming back blank
But the ids come in array format? Puts the format of the ids return.
– LeAndrade
will ta in array I have already formatted I have 2 arrays one with the list of the ids of the people who already have on the screen and the other with the list of the last 9 people who passed on the site
– Jasar Orion
var json = [9,8,7,6,5,4,3,2,1], screen = [4,2];
– Jasar Orion
would be so if it were set in the hand
– Jasar Orion