I wish to create a set interval of x milliseconds in the console logging of data. Any ideas on the code I will need to do this? Here is my code:
// API
var apiUrl = 'http://theurl.com';
// AJAX
jQuery.ajax ({
url: apiUrl,
type: 'GET',
dataType: 'json',
success: function(data) {
console.log(data);
// COORDINATES
var coordLat = data.coord.lat;
var coordLng = data.coord.lon;
2
Answers
If you wish to set an interval when logging data to the console,
you should neither need to use Ajax nor jQuery.
Instead, you can achieve this with a single line of javascript, using the
setInterval
method.The example below logs a message to the console every
900
milliseconds.Working Example:
Looking at your code I think you want to update data periodically.
So this is an example based on your code: