主要用来记录一些学到的东西,代码全部经常过实测有效,增加注释。
asp ajax post 实现整数加法过程
HTML部分
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html >
<head >
<meta http-equiv ="Content-Type" content ="text/html; charset=UTF-8" >
<title > asp ajax post 实现整数加法过程 </title >
<script type ="text/javascript" >
function createXMLHttp () {
if (window.ActiveXObject){
var version = ['Msxml2.XMLHTTP.6.0' ,'Msxml2.XMLHTTP.5.0' ,'Msxml2.XMLHTTP.4.0' ,'Msxml2.XMLHTTP.3.0' ,'Msxml2.XMLHTTP' ,'Microsoft.XMLHTTP' ];
for (var i=0 ,len=version.length; i<len; i++){
var ajaxObj = new ActiveXObject(version[i]);
if (ajaxObj){
break
}
}
} else {
var ajaxObj = new XMLHttpRequest();
}
return ajaxObj;
}
function loadName () {
var xmlHttp = createXMLHttp();
var a = document.getElementById("a" ).value
var b = document.getElementById("b" ).value
var content = encodeURI ('a=' +a+'&' +'b=' +b);
xmlHttp.open("post" , "getAjaxName.asp?" , true );
xmlHttp.onreadystatechange=function () {
if (xmlHttp.readyState==4 && xmlHttp.status==200 ){
document.getElementById("c" ).value=xmlHttp.responseText;
}
};
xmlHttp.setRequestHeader("Content-type" ,"application/x-www-form-urlencoded" );
xmlHttp.send(content);
}
</script >
</head >
<body >
<div style ="text-align: center;" >
<div >
<form id ="form1" name ="form1" method ="post" action ="" >
<input type ="text" id ="a" name ="a" /> +
<input type ="text" id ="b" name ="b" />
<input type ="button" onclick ="loadName()" value ="计算" />
<input type ="text" id ="c" name ="c" />
</form >
</div >
</div >
</body >
</html >
getAjaxName.asp部分
<%
c=cint (request .form("a" ))+cint (request .form("b" ))
response .write(c)
%>
asp ajax get 实现整数加法过程
html部分
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html >
<head >
<meta http-equiv ="Content-Type" content ="text/html; charset=UTF-8" >
<title > asp ajax get 实现整数加法过程 </title >
<script type ="text/javascript" >
function createXMLHttp () {
if (window.ActiveXObject){
var version = ['Msxml2.XMLHTTP.6.0' ,'Msxml2.XMLHTTP.5.0' ,'Msxml2.XMLHTTP.4.0' ,'Msxml2.XMLHTTP.3.0' ,'Msxml2.XMLHTTP' ,'Microsoft.XMLHTTP' ];
for (var i=0 ,len=version.length; i<len; i++){
var ajaxObj = new ActiveXObject(version[i]);
if (ajaxObj){
break
}
}
} else {
var ajaxObj = new XMLHttpRequest();
}
return ajaxObj;
}
function loadName () {
var xmlHttp = createXMLHttp();
var a = document.getElementById("a" ).value
var b = document.getElementById("b" ).value
var content = encodeURI ('a=' +a+'&' +'b=' +b);
xmlHttp.open("get" , "getAjaxName.asp?" +content, true );
xmlHttp.onreadystatechange=function () {
if (xmlHttp.readyState==4 && xmlHttp.status==200 ){
document.getElementById("c" ).value=xmlHttp.responseText;
}
};
xmlHttp.send(null );
}
</script >
</head >
<body >
<div style ="text-align: center;" >
<div >
<input type ="text" id ="a" name ="a" /> +
<input type ="text" id ="b" name ="b" />
<input type ="button" onclick ="loadName()" value ="计算" />
<input type ="text" id ="c" name ="c" />
</div >
</div >
</body >
</html >
getAjaxName部分
<%
c=cint (request .querystring("a" ))+cint (request .querystring("b" ))
response .write(c)
%>