我有这个函数:
function sendCommand(id, ip, command) {
var xmlhttp = makeRequestObject();
var file = 'http://example.com/ajaxaccessdata.php?ip=';
xmlhttp.open('GET', file + ip + '&command=' + command, true);
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var content = xmlhttp.responseText;
if (content) {
document.getElementById('result' + id).value = content;
}
}
}
xmlhttp.send(null)
}
我有n个textarea, id为'result1', 'result2', ..., 'resultn'
。
当我调用函数sendCommand
时,我的函数将结果放在所有文本区域中,因此sendCommand(1, 'localhost', 'A')
的结果将放在所有文本区域中,而不仅仅是在result
中。
有什么想法吗?
由于
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var content = xmlhttp.responseText;
if (content) {
var x = document.getElementsByName('result');
x[id+1].value = content;
}
}
}