ajax 总结
1.ajax.dll
Behind Code:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace Jquery_AJax
{
public partial class AjaxDll : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Ajax.Utility.RegisterTypeForAjax(typeof(AjaxDll));
}
[Ajax.AjaxMethod()]
public int ServerSideAdd(int firstNumber,int secondNumber)
{
return firstNumber + secondNumber;
}
[Ajax.AjaxMethod()]
public string[] StrArr()
{
string[] arr=new string[]{"John","Mink"};
return arr;
}
}
}
JavaScriptCode:
<script language="javascript" type="text/javascript">
function FontAnswerServer() {
// var response = AjaxDll.ServerSideAdd(100, 99);
// alert(response.value);
AjaxDll.ServerSideAdd(100, 99, ServerSideAdd_CallBack);
}
function ServerSideAdd_CallBack(response) {
if (response.error != null) {
alert(response.error);
return;
}
alert(response.value);
}
function ShowArr() {
var response = AjaxDll.StrArr().value;
var sel = document.getElementById("sel");
for (var i = 0; i < response.length; i++) {
if (sel.options.length>=response.length) {
return;
}
// var option = document.createElement("<option value=Name+" + i + ">" + response[i] + "</option>");.cr
var option = document.createElement("<option>");
sel.options.add(option);
option.innerText = response[i];
option.value = "Name" + i;
}
alert(sel.options[0].innerText);
// alert(response.value);
}
</script>