I want to use variable current
outside of my function, I tried many logic's but i just got undefined variable
in console. Is there something that i am missing or doing wrong?
var interval = null;
$(document).ready(function() {
interval = setInterval(updateDiv, 1000);
});
function updateDiv() {
var previous = "";
var postIDAPI = "http://localhost/test/json.php?shortURL=1";
$.getJSON(postIDAPI, function(json) {
var current = json.postid;
console.log('PostID : ', current);
$("#address").html(current);
if (previous !== current) {
clearInterval(interval);
};
});
};
var postID = current;
//here i want to use variable current
Thanks, Any help will be appriciated.