.net使用Javascript XMLHttpRequest在前台调用后台方法

/*--------前台JS代码-----------*/

var http_request;
function GetAjaxObject(coaInfo)
{
if (window.XMLHttpRequest) { // Mozilla, Safari
http_request = new XMLHttpRequest();
if(http_request.overrideMimeType)
{
http_request.overrideMimeType("text/xml");
}
}
else if (window.ActiveXObject) { // IE
try
{
http_request = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e)
{
try
{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
var linkUrl = "RetentionAC.aspx?val="+coaInfo;
http_request.open("POST",linkUrl,false);
http_request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
http_request.onreadystatechange = function(){
if(http_request.readyState == 4)
{
if(http_request.status == 200)
{
document.getElementById("ctl00_cphContent_hidCOAInfo").value = http_request.responseText;
}
}
};
http_request.send(null);
}

/*----------------------------------------------*/

/*----------后台C#代码----------------*/
if (Request.QueryString["val"] != null)
{
	string strResult = BllCommonCostAllocation.CheckSingleCOAInfo(Request.QueryString["val"].ToString());
	Response.Write(strResult); //CallBack函数中的responseText的值
	Response.End();//必不可少,必须要结束,否则会返回整个HTML文件
}
/*-------------------------------------*/

转载于:https://www.cnblogs.com/jake-hl/p/3756990.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值