怎样用JS把参数传道后台(在线急等)
我的程序时 <SCRIPT LANGUAGE= "JavaScript ">
function XmlPost(obj,fullName)
{
var svalue = obj.value;
var fullObj = document.all(fullName);
var webFileUrl = "?sortid= " + svalue;
//定义返回值
var result = " ";
//开始取值过程
var xmlHttp = new ActiveXObject( "MSXML2.XMLHTTP ");
xmlHttp.open( "POST ",webFileUrl, false);
xmlHttp.send( " ");
result = xmlHttp.responseText;
//如果有取到值,则根据格式进行拆分
//注意如果选择了第一行 "请选择 "空行时,是取不到值的,因此多加了一个条件
if(result = ! " " && svalue != " ")
{
//先清空原有的值
//fullObj.length=0;
//拆分值成数组
var piArray = result.split( ", ");
alert( "k ");
//循环数组
for(var i=0;i <piArray.length;i++)
{
//再拆分成ID及名称
var ary1 = piArray[i].toString().split( "| ");
//逐一添加项
fullObj.options.add(new Option(ary1[1].toString(),ary1[0].toString()));
}
}
else
{
//如果没有取到值,则清空要填充的下拉框的值
fullObj.length = 0;
fullObj.options.add(new Option( "请选择 ", " "));
}
}
c#是
if(!this.IsPostBack)
{
this.DownBind1();
this.DownBind2(sortid);
}
那里错了啊?就是前台的值传不过去
------解决方案--------------------//初始化httprequest对象
function InitAjax()
{
var ajax = false;
if(window.XMLHttpRequest)
{
ajax = new XMLHttpRequest();
if(ajax.overrideMimeType)
http_request.overrideMimeType( "text/xml ");
}
else if(window.ActiveXObject)
{
try
{ ajax = new ActiveXObject( "Msxml2.XMLHTTP ");}
catch(e)
{ try{ajax = new ActiveXObject( "Microsoft.XMLHTTP ");
}catch(e){}
}
}
if(!ajax)
{
alert( "不能创建XMLHttpRequest对象实例 ");
return null;
}
return ajax;
}
//
function AjaxPost(url,param,fSuccess,fError,modle)
{
var ajaxPost = InitAjax();
ajaxPost.open( "POST ",url,modle);
ajaxPost.setrequestheader( "content-length ",param.length);
ajaxPost.setRequestHeader( "Content-Type ", "application/x-www-form-urlencoded ");
ajaxPost.onreadystatechange = function()
{
if(ajaxPost.readyState == 4 && ajaxPost.status == 200)
{
var xmlBack = ajaxPost.responseXml;
if(typeof(eval(fSuccess))!= "undefined ")
eval(fSuccess)(xmlBack,ajaxPost.responseText);
}
else if(ajaxPost.readyState == 4)
{
if(typeof(eval(fError))!= "undefined ")
eval(fError)();
}
}
ajaxPost.send(param);
}
------解决方案--------------------仅供参考,param是需要回传的参数列表,格式为sep=1&id=abd&name=snowdish
后台获取为:string userName = this.Request.Form[ "id "];