How do I clear data I got in a database search using ajax?

0

How do I clear data I got from 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(){

    },
  });
});
    
asked by anonymous 13.06.2016 / 20:34

1 answer

0

You're probably experiencing 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> to every newly created url. This causes no two urls to be the same and the server cache has no effect.

    
13.06.2016 / 20:47