How do I clean data that I picked up in a database search using ajax?

Asked

Viewed 72 times

0

How do I clean data that I picked up in a database search using ajax? Because when I do a second search it merges the searched data.

var nuevos_marcadores = [];
var marcadores_bd= [];
var mapa = null;
function limpiar_marcadores(lista)
{
  for(i in lista)
  {
    lista[i].setMap(null);
  }
}
var formulario = $("#form1");
var punto = new google.maps.LatLng(-3.0774376970512085,-59.997711181640625);
var config = {
  zoom:11,
  center:punto,
  mapTypeId: google.maps.MapTypeId.ROADMAP
};
mapa = new google.maps.Map( $("#mapa")[0], config );

$("#btn_buscar").on("click", function(){
  var passar = $("#genero").val();
  $.ajax({
    type:"POST",
    url:"iajax.php",
    dataType:"JSON",
    data:"palabra_buscar="+passar+"&tipo=buscar",
    success:function(data){
      if(data.estado=="ok")
      {
        $.each(data.mensaje, function(i, item){
          var posi = new google.maps.LatLng(item.latitude, item.longitude);//bien
          var marca = new google.maps.Marker({
            position:posi,
            icon:item.marcador,
            titulo: item.nome_celula,
            endereco: item.endereco,
            cx:item.latitude,
            cy:item.longitude
          });

          google.maps.event.addListener(marca, "click", function(){
            var contentString = '<div style="color:#FF4000"><strong>Celula:</strong> ' + marca.titulo + '</div> <div><strong>Endereço:</strong> '+ marca.endereco + '</div>';
            var infowindow = new google.maps.InfoWindow({
              content: contentString
            });
            marca.addListener('click', function() {
              infowindow.open(mapa, marca);
            });
          });
          marcadores_bd.push(marca);
          marca.setMap(mapa);
        });
      }
      else
      {
        alert("Não tem Celulas Cadastradas");
      }
    },
    beforeSend:function(){

    },
    complete:function(){

    },
  });
});

1 answer

0

You are probably facing an AJAX cache problem.

You can disable it globally with the following command:

$.ajaxSetup({ cache: false })

What jQuery does is add a parameter &_=<time stamp> for every new url created. This makes there are no two identical urls and the server cache has no effect.

  • but, taking note of your code, you may need to clear the array marcadores_bd before starting the request.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.