JS
<script type="text/javascript">
function login() {var username = document.getElementById("txtUsername").value;
var password = document.getElementById("txtPassword").value;
var url = "Login.aspx?op=1";
var postStr = "username="+ username +"&password="+ password;
var ajax = null;
if (window.XMLHttpRequest) {
ajax = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
ajax = new ActiveXObject("Microsoft.XMLHTTP");
}
else {
return;
}
ajax.open("POST",url,true);
ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
ajax.send(postStr);
ajax.onreadystatechange = function() {
if (ajax.readyState == 4 && ajax.status == 200) {
document.getElementById("content").innerHTML = ajax.responseText; ;
}
}
}
</script>
html:
<div> 用户名: <input type="text" id="txtUsername" /> 密码: <input type="password" id="txtPassword" /> <input type="button" id="btnOk" value="确定" onclick="login()"/> <div id="content"></div> </div>