给你看下我的做法。
页面里准备一个空的select:
jquery写法:
$.ajax({
type: "GET",
url: "Handler/Handler.ashx",
data: "action=getCategories&value=",
cache: true,
success: function(returnvalue) {
$("#selSearchCategories").append(rvarray[1]);
}
});
在ashx处理文件中:
public void ProcessRequest(HttpContext context)
{
//context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
string value = context.Request.QueryString["value"];
string returnvalue = "false";
DataTable objDT;
try
{
if (context.Request.UrlReferrer.Authority != ConfigurationManager.AppSettings["allowDomain"])
{
throw new Exception("非法请求!");
}
switch (context.Request.QueryString["action"])
{
case "getCategories":
GoodsCategoriesEntity objGoodsCategoriesEntity = new GoodsCategoriesEntity();
GoodsCategoriesAction objGoodsCategoriesAction = new GoodsCategoriesAction(Common.GetConfigFilePath(), Common.GetElementName());
objGoodsCategoriesEntity.GCFid = 0;
objDT = objGoodsCategoriesAction.ByGCFidValid(null, objGoodsCategoriesEntity);
string returnvalue = "";
foreach (DataRow objDataRow in objDT.Rows)
{
returnvalue += "";
}
context.Response.Write(returnvalue);
break;
default:
context.Response.Write(returnvalue);
break;
}
}
catch (Exception ex)
{
context.Response.Write(ex.Message);
}
}
也就是,在处理文件中,将数据处理好,要使用的数据拼接成