Find data in Json and display time in time and move to javascrtipt

0

I need to get the data that is in json format example:

{"latitude": "-3,3462, -60,6790"}

I need to display the results time in type every 5 seconds and move to the javascript without giving refresh on the page.

  

javascript

var testMarker = L.marker([-3.3462, -60.6790],{icon: orangeIcon}).bindPopup('Kedson<br>Visto: 12:00pm');
    
asked by anonymous 13.04.2017 / 16:14

2 answers

0

You can do a ajax query that at the end of the query it throws a setTimeout in time for the next update, the jquery code would look something like this:

function updateData(){
  $.post( "/echo/json/",{}, function( data ) {
    /* Atualiza os dados */
    setTimeout(updateData,5000);
  });
}
updateData();
    
13.04.2017 / 16:39
0

Using $.getJSON of jQuery

You can use code similar to this in which you put a timer to update every 5 seconds, which fetches a JSON via ajax and updates something via JS when it returns.

setInterval( function () {
  $.getJSON("endereco_da_pagina_com_coordendas.php", function (data) {
      // codigo para atualizar o JS, exemplo:
      // se o JSON que retornar do PHP for '{coordenadas: [x, y]}'
      var testMarker = L.marker(data.coordenadas, {icon: orangeIcon}).bindPopup('Kedson<br>Visto: 12:00pm'); 
  });
}, 5000);
    
13.04.2017 / 16:43