标签:
function createAjax() {
var ajaxObject = false;
try {
ajaxObject = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
ajaxObject = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
ajaxObject = false;
}
}
if (!ajaxObject && typeof (XMLHttpRequest) != ‘undefinded‘) {
ajaxObject = new XMLHttpRequest();
}
return ajaxObject;
}
<script type="text/javascript">
var ajaxObject;
window.onload = function () {
ajaxObject = createAjax();
getControl("btnOK").onclick = submitData1;
}
function submitData1() {
var txtName = getControl("txtName").value;
//以Post方式请求发送请求
ajaxObject.open("POST", "ResponseEnd.aspx", true);
//以Post方式发送异步请求需要设置请求头
ajaxObject.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
ajaxObject.onreadystatechange = function () {
if (ajaxObject.readyState == 4) {
//状态200表示异步对象已经完全接收完服务器响应的数据
if (ajaxObject.status == 200) {
var res = ajaxObject.responseText;
alert(res);
}
}
}
//发送异步请求(Post方式发送请求在send里面书写自己要发送给服务器的参数)
ajaxObject.send("flag=1&name=" + txtName);
}
</script>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace Web { public partial class ResponseEnd : System.Web.UI.Page { protected void Page_Load( object sender, EventArgs e) { if (! string .IsNullOrEmpty(Request[ "flag" ])) { ShuChu(); } } private void ShuChu() { #region 方法一 //try //{ // string name = Request["name"]; // Response.Write(name); //} //catch (Exception ex) //{ // throw new Exception(ex.Message); //} //finally //{ // Response.End(); //} #endregion #region 方法二 //try //{ // string name = Request["name"]; // Response.Write(name); // this.Page.Visible = false; // Context.ApplicationInstance.CompleteRequest(); //} //catch (Exception ex) //{ // throw new Exception(ex.Message); //} #endregion try { string name = Request[ "name" ]; Response.Write(name); Response.End(); } catch (System.Threading.ThreadAbortException ex) { } catch (Exception ex) { throw new Exception(ex.Message); } } } } |
标签:
原文地址:http://www.cnblogs.com/liangxiaofeng/p/5642761.html