I have created a function that performs an ajax query with data return in json, when this function receives the data, it checks if the DOM exists, if it does not exist, it creates it.
The question is: When the DOM exists instead of creating it, you must change the data within that DOM.
Example:
function getInfo(clas, div, ty) {
$.get('MI ARCHIVO PHP?t=' + ty, function(data){
if($(div).length == 0) {
clas.append('<div class="' + div + '">' + data.text + '</div>');
}else{
$(div).html(data.text);
}
}, 'json');
}
The thing is that, the first time it works perfectly, I create the div with the correct information, but the second when I call the function with a setInterval instead of changing the information inside the div, what it does is repertirme it constantly, I mean , that on the screen I end up with a lot of div with the same class.
The variables of the function are: getInfo ($ ('. infobox'), '.info', 0); The first refers to a div that already comes within the html file, the second is the class of the div that you have to create or modify and the third part of the php file in the ajax. I must say that the "infobox" contains several information boxes, and always repeats them to me.
What am I doing wrong?
Thanks in advance.