0
選択リストにjavascriptで得た値を入力するにはどうすればいいですか?リストの値がjavacriptで設定されている
私はJSON形式で私に応答を与える.phpサイトにGETリクエストを送信しています。今私は選択リストに入れた行を入れたいと思う。
<select id = "list" name=log size=50 style=width:1028px>
<script type="text/javascript">
window.onload = function() {
var bytes=0;
var url = "/test/log.php?q='0'";
function httpGet(url)
{
var xhttp = new XMLHttpRequest();
var realurl = url + bytes;
xhttp.open("GET", url, true);
xhttp.onload = function (e) {
if (xhttp.readyState === 4) {
if (xhttp.status === 200) {
console.log(xhttp.responseText);
var response=JSON.parse(xhttp.responseText);
var log = response.key;
bytes = log.length;
}
};
xhttp.onerror = function (e) {
console.error(xhttp.statusText);
}
};
xhttp.send();
}
var updateInterval = 2000;
function update() {
httpGet(url);
setTimeout(update, updateInterval);
}
update();
}
</script>
</select>
私はlog.php
から取得応答が"{"key":"whole log file"}"
です。今、私はその応答をリストに保存し、2秒ごとにそれを設定したいと思います。
はどのようにあなたがそれを達成したいですか? PHPまたはJavascriptを使用して? –
JavaScriptを使用しています。私は、ページをリフレッシュすることなく、リストに値を設定したい。 – Mirakurun