首页 > 代码库 > .net使用Ajax在前台调用后台方法

.net使用Ajax在前台调用后台方法

/*--------前台JS代码-----------*/	
var http_request;
function GetAjaxObject(coaInfo)
{
     //根据浏览器的不同来获取XMLHttpRequest对象 if (window.XMLHttpRequest) { // Mozilla, Safari, ... http_request = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE http_request = new ActiveXObject("Microsoft.XMLHTTP"); }
     //设置XMLHttpRequest对象的参数 var linkUrl = "RetentionAC.aspx?val="+coaInfo; var queryString = "vasl="+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://www.mamicode.com/http_request.responseText;"val"] != null) { string strResult = BllCommonCostAllocation.CheckSingleCOAInfo(Request.QueryString["val"].ToString()); Response.Write(strResult); //CallBack函数中的responseText的值 Response.End();//必不可少,必须要结束,否则会返回整个HTML文件 } /*-------------------------------------*/