问题描述
i在页面加载时称为webmethod,如下所示:
i called a webmethod on page load like this:
var objdata= PageMethods.LoadChart(onSucess, onError);
这是我的webmethod:
here is my webmethod:
[WebMethod]
public static string LoadChart()
{
String daresult = null;
List<SqlParameter> sc = new List<SqlParameter>();
DataSet ds = new DBCommonFunctions().ExecuteProcedure("crm_new_country_sale_chart", sc);
DataTable dt = new DataTable();
if (ds != null)
{
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
dt = ds.Tables[0];
//dt.WriteXml("abc.xml");
daresult = DataSetToJSON(dt);
}
}
}
return daresult;
}
public static string DataSetToJSON(DataTable dt)
{
Dictionary<string, object> dict = new Dictionary<string, object>();
//foreach (DataTable dt in ds.Tables)
//{
object[] arr = new object[dt.Rows.Count + 1];
for (int i = 0; i <= dt.Rows.Count - 1; i++)
{
arr[i] = dt.Rows[i].ItemArray;
}
dict.Add(dt.TableName, arr);
//}
JavaScriptSerializer json = new JavaScriptSerializer();
return json.Serialize(dict);
}
i在客户端得到以下结果:
{表:[[下午2点-3 PM,0,0,0。05,0,2014年1月20日下午2:02,[3 PM-4 PM,0,0,0.000,0,Jan 20 2014年3:02 PM],[4 PM-5 PM,0,0,0。05,0,2014年1月20日下午4:02],[下午5点至下午6点,0 ,0,0。05,0,2014年1月20日下午5:02,[6 PM-7 PM,0,0,0。05,0,2014年1月20日下午6:02] ,[7 PM-8 PM,0,0,0.000,0,2014年1月20日7:02 PM],[8 PM-9 PM,0,0,0.000 ,0,2014年1月20日8:02 PM,[9 PM-10 PM,0,0,0.000,0,2014年1月20日9:02 PM],10 PM-11 PM,0,0,0.000,0,2014年1月20日10:02 PM,[11 PM-12 AM,0,0,0。05,0,2014年1月20日11:02 PM],[12 AM-1 AM,0,0,0.000,0,2014年1月21日12:02 AM],[1 AM-2 AM,0, 0,0.000,0,2014年1月21日上午1:02,[2 AM-3 AM,0,0,0。05,0,2014年1月21日上午2:02],[ 凌晨3点 - 凌晨4点,0,0,0。05,0,2014年1月21日上午3点02分,[4 AM - 5 AM,0,0,0.000,0 ,2014年1月21日上午4:02,[上午5点至上午6点,0,0,0。05,0,2014年1月21日上午5点02分],早上6点至早上7点 ,0,0,0.000,0,2014年1月21日上午6:02 ],[7 AM-8 AM,CN-000044,United States,249.990,1,2014年1月21日上午7:02],[8 AM-9 AM,0, 0,0。05,0,2014年1月21日上午8:02,[上午9点 - 上午10点,0,0,0。05,0,2014年1月21日上午9点02分],[ 10 AM-11 AM,0,0,0.000,0,2014年1月21日上午10:02,[上午11点至下午12点,0,0,0.000,0, 2014年1月21日上午11:02,[12 PM-1 PM,0,0,0.000,0,2014年1月21日下午12:02],[1 PM-2 PM, 0,0,0.000,0,2014年1月21日1:02 PM],null]}
现在我想在我的javascript函数中读取这个返回的结果
i get the following result on client side:
{"Table":[["2 PM-3 PM","0","0",0.000,0,"Jan 20 2014 2:02PM"],["3 PM-4 PM","0","0",0.000,0,"Jan 20 2014 3:02PM"],["4 PM-5 PM","0","0",0.000,0,"Jan 20 2014 4:02PM"],["5 PM-6 PM","0","0",0.000,0,"Jan 20 2014 5:02PM"],["6 PM-7 PM","0","0",0.000,0,"Jan 20 2014 6:02PM"],["7 PM-8 PM","0","0",0.000,0,"Jan 20 2014 7:02PM"],["8 PM-9 PM","0","0",0.000,0,"Jan 20 2014 8:02PM"],[" 9 PM-10 PM","0","0",0.000,0,"Jan 20 2014 9:02PM"],["10 PM-11 PM","0","0",0.000,0,"Jan 20 2014 10:02PM"],["11 PM-12 AM","0","0",0.000,0,"Jan 20 2014 11:02PM"],["12 AM- 1 AM","0","0",0.000,0,"Jan 21 2014 12:02AM"],[" 1 AM- 2 AM","0","0",0.000,0,"Jan 21 2014 1:02AM"],[" 2 AM- 3 AM","0","0",0.000,0,"Jan 21 2014 2:02AM"],[" 3 AM- 4 AM","0","0",0.000,0,"Jan 21 2014 3:02AM"],[" 4 AM- 5 AM","0","0",0.000,0,"Jan 21 2014 4:02AM"],[" 5 AM- 6 AM","0","0",0.000,0,"Jan 21 2014 5:02AM"],[" 6 AM- 7 AM","0","0",0.000,0,"Jan 21 2014 6:02AM"],[" 7 AM- 8 AM","CN-000044","United States",249.990,1,"Jan 21 2014 7:02AM"],[" 8 AM- 9 AM","0","0",0.000,0,"Jan 21 2014 8:02AM"],[" 9 AM-10 AM","0","0",0.000,0,"Jan 21 2014 9:02AM"],["10 AM-11 AM","0","0",0.000,0,"Jan 21 2014 10:02AM"],["11 AM-12 PM","0","0",0.000,0,"Jan 21 2014 11:02AM"],["12 PM- 1 PM","0","0",0.000,0,"Jan 21 2014 12:02PM"],[" 1 PM- 2 PM","0","0",0.000,0,"Jan 21 2014 1:02PM"],null]}
now i want to read this returned result in my javascript function
推荐答案
<script type="text/javascript">
这篇关于如何从webmethod返回数据表并在javascript中读取它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!