How to parse variable return back in setInterval
The code below will get every second a price from a .json file.
What i need is the result to be parsed back into the updateRate function
in order to compare the previous price with the newly updated one...
I've googling a lot lot, and some say to use .bind or an anonymous function
but i am stuck. What's the way to go here?
- $(document).ready(function () {
function updateRate(type, price) {
$.ajax({
url: './json/get_price.php',
datatype: "json",
data: { t: type, c: price }, //t=type
success: function(data) {
var price = data["price"];
$("#status").html(data["price"]);
console.log("t=" + type + " price=" + price );
}
});
}
var myVar;
var price = '0';
myVar = setInterval(updateRate.bind(null,"buy",price),1000);
});