前端: $.getJSON("http://stock.emoney.cn/DefaultTest.aspx", function (data) {
alert(data.toString());
$("#div001").html(data.toString());
//alert(result);
var obj = $("#tabLia .current")[0]
var index = $("#tabLia li").index(obj);
$("#tabLia_c" + index).show();
});
后台是返回字符串:
protected string showIdx_idx()
{
StringBuilder sb = new StringBuilder();
string[] ArrIdx = new string[] { "000001", "399001", "000300", "399101", "399006", "global" };
string str = Pub.LoadData(jsonUrl + "hangqing/hyzyzslb.ashx");
List<ZshqEnty> list = JsonConvert.DeserializeObject<List<ZshqEnty>>(str);
List<ZshqEnty> list2 = new List<ZshqEnty>();
for (int i = 0; i < ArrIdx.Length; i++)
{
switch (i)
{
case 0:
case 1:
case 2:
case 3:
case 4:
list2 = list.Where(x => x.code == ArrIdx[i]).ToList();
if (list2.Count > 0)
{
sb.AppendFormat("<div class=\"chart\" id=\"tabLia_c{0}\" style=\"display:block;\">", i);
sb.AppendFormat("<div class=\"data\">");
string cls = "red";
if (OTO.ToDecimal(list2[0].D, 0) < 0)
cls = "green";
sb.AppendFormat("<div class=\"{0}\">", cls);
sb.AppendFormat("<a href=\"{2}Dp{1}.shtml\" class=\"b\">{0}</a> ", list2[0].scmc, list2[0].code, quoteUrl);
sb.AppendFormat("<span class=\"font14\">");
if (OTO.ToDecimal(list2[0].P, 0) == 0)
{
sb.AppendFormat("- ");
sb.AppendFormat("- ");
sb.AppendFormat("-</span>");
}
else
{
sb.AppendFormat("{0} ", OTO.ToDecimal(list2[0].P, 0));
sb.AppendFormat("{0} ", OTO.ToDecimal(list2[0].D, 0));
sb.AppendFormat("{0}</span>", OTO.ToDecimal(list2[0].F, 1, 2, "%", "-"));
}
sb.AppendFormat("</div>");
sb.AppendFormat("</div>");
sb.AppendFormat("<a href=\"{1}DP{0}.shtml\" target=\"_blank\"><img src=\"http://www.ymcps.com/images/zhishunew/{0}.jpg\" alt=\"\" width=\"230\" height=\"120\" /></a>", ArrIdx[i], quoteUrl);
sb.AppendFormat("</div>");
}
break;
case 5:
sb.AppendFormat("<div class=\"chart\" style=\"display:none;\" id=\"tabLia_c{0}\">", i);
sb.AppendFormat("<div class=\"global\">");
string con = Pub.LoadData(jsonUrl + "stock/zhishu.ashx?code=HSI,dji,nasdaq,GC,CL");
List<StockZhiShuEnty> list3 = Newtonsoft.Json.JsonConvert.DeserializeObject<List<StockZhiShuEnty>>(con);
if (list3 != null && list3.Count > 0)
{
sb.AppendFormat("<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">");
foreach (var m in list3)
{
sb.AppendFormat("<tr>");
sb.AppendFormat("<td style=\"color:#0D519C;\">{0}</td>", m.CnCode);
sb.AppendFormat("<td class=\"{1}\">{0}</td>", OTO.ToDecLine(m.zs, 2, "-", ""), OTO.ToDecimal(m.zd, 0) >= 0 ? "red" : "green");
sb.AppendFormat("<td class=\"{1}\">{0}</td>", OTO.ToDecLine(m.zd, 2, "-", ""), OTO.ToDecimal(m.zd, 0) >= 0 ? "red" : "green");
sb.AppendFormat("<td class=\"{1}\">{0}</td>", OTO.ToDecLine(m.zdf, 2, "-", ""), OTO.ToDecimal(m.zd, 0) >= 0 ? "red" : "green");
sb.AppendFormat("</tr>");
}
sb.AppendFormat("</table>");
}
sb.AppendFormat("</div>");
sb.AppendFormat("</div>");
break;
}
}
return sb.ToString();
}