I have a webservice in json that returns me to the last people who passed in a certain place.
That said, I did the following:
-
I always ask for information about the last person to go to the api.
-
I created in my page in
setInterval
1s to read this api and make aprepend
with the information of this json on the screen within a div
I have 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 the api default to always return the last 9 people 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 do not have on the screen so I can include them in prepend. Can anyone help me with this question of what 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 vasio
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);
and if I do
console.log(tela);
it returns
{317,318}
and I do
console.log(api);
it returns {322,321,319,318,317,316,315,314,313}
Then the add should be {322,321,319,316,315,314,313}
But it is coming back blank