有些元素需要异步接收信息并在单击按钮时显示在单独的块中,但我不知道如何做到这一点。
没有任何库。
以下是我的努力:
<script>
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if(xhr.readyState === 4) {
document.getElementById('ajax').innerHTML = xhr.responseText;
}
};
</script>
<ul>
<script>
xhr.open('GET','function_snmp.php?id=1')
function sendAJAX() {
xhr.send();
}
</script>
<li>город Екатеринбург, улица Сельская, дом 6</li>
<button onclick="sendAJAX()" class="button">Подробнее</button>
<div id="ajax"></div>
</ul>
<ul>
<script>
xhr.open('GET','function_snmp.php?id=2')
function sendAJAX() {
xhr.send();
}
</script>
<li>город Москва, улица Московская, дом 5</li>
<button onclick="sendAJAX()" class="button">Подробнее</button>
<div id="ajax"></div>
</ul>
最初,您在布局中有错误;您不能设置相同的两个块
id
,您可以这样做:在“function_snmp.php”页面上形成所需的html