Hi mọi người,
Mình có một vấn đề thế này, ngay chổ thẻ BUTTON, phải có sự kiện nhấn nút, thì hàm stateUpdate() chạy và xuất dữ liệu ra thẻ H1. Bây giờ mình muốn hỏi là làm cách nào để ngay thẻ H1 luôn hiện dữ liệu lấy từ hàm stateUpdate() mà không cần phải nhấn nút. Mình cảm ơn!
<script type="text/javascript">
var HTTPrequest = new XMLHttpRequest();
function stateUpdate(){
HTTPrequest.onreadystatechange = function(){
if(this.readyState == 4 && this.status == 200){
document.getElementById("state").innerHTML = this.responseText;
}
};
HTTPrequest.open("GET", "state.asp", true);
HTTPrequest.send();
</script>
.
.
.
<button type="button" onclick="stateUpdate();">Request data</button>
<h1 id="state"></h1>
.
.
.