我有一段代码将 div 标签的内部 HTML 更改为状态消息,这包含在 try 方法中,唯一的问题是状态保持可见大约 3 秒然后消失。我想这是由于 try 方法,有什么办法可以阻止它?
<script>
function goCouch(form){
var xmlHttp = false;
try {
var couchURL = form.inputbox.value;
xmlHttp = new XMLHttpRequest();
xmlHttp.open( "GET", "http://" + couchURL + ":5984", false );
xmlHttp.send( null );
var couchWelcome = xmlHttp.responseText;
var requestedServerStatus = xmlHttp.status;
var status = document.getElementById("status")
status.innerHTML = couchWelcome;
//alert(requestedServerStatus);
//alert(couchWelcome);
} catch (failed) {
xmlHttp = false;
}
if (!xmlHttp){
//alert("Don't panic, but I can't connect to that server.");
}
}
</script>
<div id="mainContent">
<form action="" method="get" id="myform">
Enter your database URL<br>
<input type="url" name="inputbox" value="">
<input type="submit" name="button" value="Go" onclick="goCouch(this.form)"></p>
</form>
<div id="status"></div>
</div>