.net中ajax前台使用
我是在开发时候使用的,受一个功能点的需求,使用了ajax,最为基础的方法。如下的方法:
从前台界面获取NEWSERIAL控件的内容,通过ajax传递参数NEWSERIAL到页面ajax.aspx。然后在ajax.aspx页面接受NEWSERIAL做处理,可以使用Session等操作储存值使用的。
function myAjax(){
var postData="NEWSERIAL=0";
postData = "NEWSERIAL=" + document.getElementById('S_NEWSERIAL').value + 'ω' + document.getElementById('S_OLDSERIAL').value;
var xmlhttp=null;
xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
xmlhttp.open('POST', 'ajax.aspx' , false);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send(postData);
if(xmlhttp.readyState==4)
{
data=xmlhttp.responseText;
}
}
aspx.cs
string str= Request.Params["NEWSERIAL"] == null ? "" : Request.Params["NEWSERIAL"].ToString();