AJAX入门问题就难倒了我,各位高手请帮我看一看
//第一个页面的代码 Default1.aspx
<html>
<head>
<title> Default1.aspx </title>
<script language= "javascript ">
var xmlHttp;
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp=new ActiveXObject( "Microsoft.XMLHTTP ");
}
else if(window.XMLHttpRequest)
{
xmlHttp=new XMLHttpRequest();
}
}
function updateTotal()
{
frm=document.forms[0];
url= "Default2.aspx?A= "+frm.elements[ 'A '].value+ "&B= "+frm.elements[ 'B '].value;
xmlHttp.open( "GET ",url,true);
xmlHttp.onreadystatechange=doUpdate;
xmlHttp.send();
return false;
}
function doUpdate()
{
if(xmlHttp.readyState==4)
{
document.forms[0].elements[ 'TOT '].value=xmlHttp.responseText;
}
}
</script>
</haed>
<body onload= "createXMLHttpRequest(); ">
<form>
<table width= "300 " height= "143 ">
<tr vAlign= "top ">
<td> First value </td>
<td> <Input type= "text " id= "A " value= "0 " onkeyup= "updateTotal(); "> </td>
</tr>
<tr vAlign= "top ">
<td> Second value </td>
<td> <Input type= "text " id= "B " value= "0 " onkeyup= "updateTotal(); "> </td>
</tr>
<tr vAlign= "top ">
<td> Return value </td>
<td> <Input type= "text " id= "TOT " value= "0 "> </td>
</tr>
</table>
</form>
</body>
</html>
//第二个页面的代码 Default2.aspx
private void Page_load(object sender,System.EventArgs e)
{
int a=0;
int b=0;
if(Request.queryString[ "A "]!=null)
{
a=Convert.ToInt32(Request.QueryString[ "A "].ToString());
}
if(Request.queryString[ "B "]!=null)
{
a=Convert.ToInt32(Request.QueryString[ "B "].ToString());
}
Response.Write(a+b);
}
运行时输入值后没有任何反应,请问这是怎回事?
------解决方案--------------------1, 你这写法没有错误
2, 这里直接使用javascript就可以计算了,不需要使用ajax