<script type="text/javascript">
function AddNumbers()
{
// Create an instance of the HTTP Request Object
var xmlHttp = new XMLHttpRequest();
var value1 = document.getElementById("txtValue1").value;
var value2 = document.getElementById("txtValue2").value;
// Specify HTTP POST so that parameters can be passed in
// request body
xmlHttp.open("POST", "add.aspx", false);
// Send the parameters in CSV format
xmlHttp.send(value1 + "," + value2);
var result = document.getElementById("spanResult");
// Use result of calculation from server
result.innerHTML = xmlHttp.responseText;
}
</script>
...
<form>
<input id="txtValue1"/>
<input id="txtValue2"/>
<input onclick="AddNumbers();"type="button" value="Add"/>
<p>Result:</p>
<span id="spanResult"></span>
</form>
这个是原例子,跟你的要求一样:http://www.httpwatch.com/httpgallery/ajax/
上面的我是看懂了,可是在add.aspx的页面中怎么写啊,刚才试了好多方法没有写出来!还请在详细讲解一下!谢谢
add.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
int a = Convert.ToInt32(Request["a"]);
int b = Convert.ToInt32(Request["b"]);
Response.Write(a+b);
}
}
}
}
删掉多余的aspx页面的多元的标签 保留<% %>这段标签,其他统统干掉!
你也可以用一个ashx页面来处理!!
祝您早日解决
a.b是你传人的两个数字
谢谢!
@舍鱼: 那现在可以实现你的功能了吗?