一个一直没有解决的问题!ajax调用返回DataSet调试时可以看到数据,但是在javascript中取值的时候老是undefined,怎么回事情呀? response从那传过来了 你贴出来没用啊 ajax哪一块你怎么做的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 webservice: [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [ToolboxItem(false)] [System.Web.Script.Services.ScriptService] public class wsAirwayArea : System.Web.Services.WebService { [WebMethod] public DataSet GetAreaByAirway(string airway) { CZY.BLL.ALINKA bll = new CZY.BLL.ALINKA(); CZY.Model.ALINKA model = new CZY.Model.ALINKA(); DataSet ds=new DataSet(); ds = bll.GetList(" airway='" + airway + "'"); return ds; } [WebMethod] public string HelloWorld() { return "Hello World"; } } /////////////////////////////////////////////// function clicked() { var airway=document.getElementById(" <%=DDLSAIRWAY.ClientID%> ").value; web.WebService.wsAirwayArea.GetAreaByAirway("ca",onSucceeded);//这里是测试的时候使用的值。 } function onSucceeded(response)//response在debug windows中可以看到返回ca的数据库中的数据。 { if (response.value != null { debugger; var ds = response.value; if(ds != null && typeof(ds) == "object" && ds != null) { for(var i=0; i <ds.Tables[0].Rows.length; i++) { var name=ds.Tables[0].Rows[i].AREA; var id=ds.Tables[0].Rows[i].AIRWAY; document.getElementById("ctl00_ContentPlaceHolder1_DDLSAIRWAY").options.add(new Option(name,id)); } } return } ajax显然不能直接返回DataSet给JS你必须将期转换为字符串后再输出为了方便处理,你最好把字符串格式化为JSON格式或数组格式,这样便于JAVASCRIPT接收处理. 哪有返回dataset出来的呀,这个不太好处理啊,还是用数组或者json格式的数据吧,不然js也不知道怎么解析 //把DataSet转换成json格式 转换成JS用 var list = new Function("retrun "+xmlHttp.responseText+"")public string ConvertToJson(System.Data.DataSet ds) { StringBuilder retVal = new StringBuilder(); int TableCount = 0, RowCount = 0, ColumnCount = 0; retVal.Append("{"); foreach (System.Data.DataTable dt in ds.Tables) { TableCount++; retVal.AppendFormat("{0}:[", dt.TableName); foreach (System.Data.DataRow row in dt.Rows) { RowCount++; retVal.Append("{"); foreach (System.Data.DataColumn column in dt.Columns) { ColumnCount++; retVal.AppendFormat("{0}:\"{1}\"{2}", column.ColumnName, row[column].ToString().Trim().Replace("'", "\\'").Replace("\\r", "<br/>").Replace("\\n", "<br/>").Replace(System.Environment.NewLine, "<br/>"), ColumnCount == dt.Columns.Count ? "" : ","); } ColumnCount = 0; retVal.Append("}"); retVal.AppendFormat("{0}", RowCount == dt.Rows.Count ? "" : ","); } RowCount = 0; retVal.Append("]"); retVal.AppendFormat(TableCount == ds.Tables.Count ? "" : ","); } retVal.Append("}"); 将你的dataset转换成json 这样js就可以进行接收和解析了 求将一个32位的随机数字符串拆分成由16个2位的字符串组成的数组的方法 asp.net 邮箱验证用户注册(跪求源码) 做过---模拟登录 请进 (winform)急。。。。。。 有关阴阳历转换 <<五一长假回家看看 为了自己的慈父>> 我好久没有哭了 看了20遍就5了20遍 WEB服务器启动不了 .net的DLL好还是asp的inc好? 在局域网中服务器找不到sqlserver是怎么回事呀? 一个小问题,关于登陆 怎么取用户IP地址? asp.net 后台不能访问前台控件 在看web.config配置,看得头晕晕的,给解惑一下把
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class wsAirwayArea : System.Web.Services.WebService
{ [WebMethod]
public DataSet GetAreaByAirway(string airway)
{
CZY.BLL.ALINKA bll = new CZY.BLL.ALINKA();
CZY.Model.ALINKA model = new CZY.Model.ALINKA();
DataSet ds=new DataSet();
ds = bll.GetList(" airway='" + airway + "'");
return ds; } [WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
///////////////////////////////////////////////
function clicked()
{
var airway=document.getElementById(" <%=DDLSAIRWAY.ClientID%> ").value; web.WebService.wsAirwayArea.GetAreaByAirway("ca",onSucceeded);//这里是测试的时候使用的值。 } function onSucceeded(response)//response在debug windows中可以看到返回ca的数据库中的数据。
{
if (response.value != null {
debugger;
var ds = response.value;
if(ds != null && typeof(ds) == "object" && ds != null)
{
for(var i=0; i <ds.Tables[0].Rows.length; i++)
{
var name=ds.Tables[0].Rows[i].AREA;
var id=ds.Tables[0].Rows[i].AIRWAY;
document.getElementById("ctl00_ContentPlaceHolder1_DDLSAIRWAY").options.add(new Option(name,id));
} }
return }
你必须将期转换为字符串后再输出
为了方便处理,你最好把字符串格式化为JSON格式或数组格式,这样便于JAVASCRIPT接收处理.
//把DataSet转换成json格式 转换成JS用 var list = new Function("retrun "+xmlHttp.responseText+"")
public string ConvertToJson(System.Data.DataSet ds) {
StringBuilder retVal = new StringBuilder();
int TableCount = 0, RowCount = 0, ColumnCount = 0;
retVal.Append("{");
foreach (System.Data.DataTable dt in ds.Tables) {
TableCount++;
retVal.AppendFormat("{0}:[", dt.TableName);
foreach (System.Data.DataRow row in dt.Rows) {
RowCount++;
retVal.Append("{");
foreach (System.Data.DataColumn column in dt.Columns) {
ColumnCount++;
retVal.AppendFormat("{0}:\"{1}\"{2}", column.ColumnName, row[column].ToString().Trim().Replace("'", "\\'").Replace("\\r", "<br/>").Replace("\\n", "<br/>").Replace(System.Environment.NewLine, "<br/>"), ColumnCount == dt.Columns.Count ? "" : ",");
}
ColumnCount = 0;
retVal.Append("}");
retVal.AppendFormat("{0}", RowCount == dt.Rows.Count ? "" : ",");
}
RowCount = 0;
retVal.Append("]");
retVal.AppendFormat(TableCount == ds.Tables.Count ? "" : ",");
}
retVal.Append("}");