【发布时间】:2020-04-29 12:19:51
【问题描述】:
我正在使用“Ion.RangeSlider”库。我正在尝试通过 JSON 加载值,但无法让滑块接受“来自”字段。我不能硬编码值,因为用户可以更改它。
$(function(){
'use strict'
$('#rt').ionRangeSlider({
min: 100,
max: 100000,
step: 10,
from: loaddata(), -> Doesn't get the data from the function even though it prints it to the console.
postfix: "ms",
prefix: "Response Time: "
});
});
function loaddata(){
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myObj = JSON.parse(this.responseText);
//document.getElementById("rt").value = myObj.response_time; -> Changing the value of the slider doesn't work as well
console.log(myObj.response_time); -> Prints 2000 to the console
return myObj.response_time;
}
};
xmlhttp.open("GET", "api/settings.json", true);
xmlhttp.send();
}
我的 json 文件:
{"response_time":7120,"led":0,"device_ip":"192.168.1.1"}
【问题讨论】:
标签: javascript json rangeslider