C#2.0下面的簡單Ajax應用
來源:互聯網
上載者:User
不帶參數的:Default.aspx.cs: public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default ));
} [AjaxMethod]
public string GetString()
{
return "test...";
}
} Default.aspx invoke:<script>function GetString()
{
Default .GetString(GetString_Callback); // asynchronous call
}function GetString_Callback(response)
{
if(response != null)
{
window.document.getElementById("TextBox1").value = response.value;
}
else
{
window.document.getElementById("TextBox1").value= "";
}
}GetString();</script>帶參數的:Default.aspx.cs: public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
AjaxPro.Utility.RegisterTypeForAjax(typeof(_Default));
} [AjaxMethod]
public string GetString(string str)
{
return str;
}
} Default.aspx invoke:<script>function GetString()
{
Default .GetString("test",GetString_Callback); // asynchronous call contain param
}function GetString_Callback(response)
{
if(response != null)
{
window.document.getElementById("TextBox1").value = response.value;
}
else
{
window.document.getElementById("TextBox1").value= "";
}
}GetString();</script>