1:获取数据的页面:
Code
1 protected void Page_Load(object sender, EventArgs e)
2 {
3 if (!IsPostBack) {
4 //是否接收参数
5 if (!string.IsNullOrEmpty(Request["type"])) {
6
7 switch (Request["type"]) {
8 case "ZXQG":
9 if (Cache["ZXQG"] == null)
10 {
11 try
12 {
13 List<XbProductProvide> PPList = new List<XbProductProvide>();
14 List<string> SearchStr = new List<string>();
15 SearchStr.Add("InfoType=2");
16 PPList = XbProductBPM.SelectProductProvideList(SearchStr.ToArray(), "ID,EnterpriseID,Title", "CreationDate DESC", 5, 0, "ID");
17 StringBuilder Sb = new StringBuilder();
18 for (int i = 0; i < PPList.Count && i < 5; i++)
19 {
20 Sb.Append("<p><a href=\"http://tg.xband.cn//SupplyDemand/Supply.aspx?provideID=" + PPList[i].ID + "&entID=" + PPList[i].EnterpriseID + "\" target=\"_blank\">" + (PPList[i].Title.Length > 15 ? PPList[i].Title.Substring(0, 15) : PPList[i].Title) + "</a></p>");
21 }
22 Cache.Insert("ZXQG", Sb.ToString(), null, DateTime.Now.AddMinutes(5), TimeSpan.Zero);
23
24 }
25 catch (Exception ex)
26 {
27 Cache.Insert("ZXQG", ex.Message, null, DateTime.Now.AddMinutes(5), TimeSpan.Zero); ;
28 }
29 finally
30 {
31 Response.Write(Cache["ZXQG"].ToString());
32 }
33 }
34 else {
35 Response.Write(Cache["ZXQG"].ToString());
36 }
37 break;
38 //最新加盟的数据
39 case "ZXJM":
40 if (Cache["ZXJM"] == null)
41 {
42 try
43 {
44 List<XbView_Enterprise_Account> ECList = new List<XbView_Enterprise_Account>();
45 List<string> SearchStr2 = new List<string>();
46 SearchStr2.Add("MemberLevel=15");
47 SearchStr2.Add(" and IndustryCategoryID='4f691d0a-9d8b-40e7-88e1-18970fe4fa74' ");
48 SearchStr2.Add(" and Name is not null");
49 ECList = XbEnterpriseBPM.SelectView_Enterprise_AccountList(SearchStr2.ToArray(), "NickName,EnterpriseId,Name", "CreationDate DESC", 6, 0, "ID");
50 StringBuilder Sb2 = new StringBuilder();
51 for (int i = 0; i < 6 && i < ECList.Count; i++)
52 {
53 Sb2.Append("<p><a href=\"http://light.xband.cn/eStore/Index.aspx?CorpID=" + ECList[i].EnterpriseID + "\">" + (ECList[i].Name.Length > 15 ? ECList[i].Name.Substring(0, 15) : ECList[i].Name) + "</a></p>");
54 }
55 Cache.Insert("ZXJM", Sb2.ToString(), null, DateTime.Now.AddMinutes(5), TimeSpan.Zero);
56 }
57 catch (Exception ex)
58 {
59 Cache.Insert("ZXJM", ex.Message, null, DateTime.Now.AddMinutes(5), TimeSpan.Zero);
60 }
61 finally
62 {
63 Response.Write(Cache["ZXJM"].ToString());
64 }
65 }
66 else {
67 Response.Write(Cache["ZXJM"].ToString());
68 }
69 break;
70 //默认无返回
71 default:
72 break;
73 }
74 }
75 }
76 }
1 protected void Page_Load(object sender, EventArgs e)
2 {
3 if (!IsPostBack) {
4 //是否接收参数
5 if (!string.IsNullOrEmpty(Request["type"])) {
6
7 switch (Request["type"]) {
8 case "ZXQG":
9 if (Cache["ZXQG"] == null)
10 {
11 try
12 {
13 List<XbProductProvide> PPList = new List<XbProductProvide>();
14 List<string> SearchStr = new List<string>();
15 SearchStr.Add("InfoType=2");
16 PPList = XbProductBPM.SelectProductProvideList(SearchStr.ToArray(), "ID,EnterpriseID,Title", "CreationDate DESC", 5, 0, "ID");
17 StringBuilder Sb = new StringBuilder();
18 for (int i = 0; i < PPList.Count && i < 5; i++)
19 {
20 Sb.Append("<p><a href=\"http://tg.xband.cn//SupplyDemand/Supply.aspx?provideID=" + PPList[i].ID + "&entID=" + PPList[i].EnterpriseID + "\" target=\"_blank\">" + (PPList[i].Title.Length > 15 ? PPList[i].Title.Substring(0, 15) : PPList[i].Title) + "</a></p>");
21 }
22 Cache.Insert("ZXQG", Sb.ToString(), null, DateTime.Now.AddMinutes(5), TimeSpan.Zero);
23
24 }
25 catch (Exception ex)
26 {
27 Cache.Insert("ZXQG", ex.Message, null, DateTime.Now.AddMinutes(5), TimeSpan.Zero); ;
28 }
29 finally
30 {
31 Response.Write(Cache["ZXQG"].ToString());
32 }
33 }
34 else {
35 Response.Write(Cache["ZXQG"].ToString());
36 }
37 break;
38 //最新加盟的数据
39 case "ZXJM":
40 if (Cache["ZXJM"] == null)
41 {
42 try
43 {
44 List<XbView_Enterprise_Account> ECList = new List<XbView_Enterprise_Account>();
45 List<string> SearchStr2 = new List<string>();
46 SearchStr2.Add("MemberLevel=15");
47 SearchStr2.Add(" and IndustryCategoryID='4f691d0a-9d8b-40e7-88e1-18970fe4fa74' ");
48 SearchStr2.Add(" and Name is not null");
49 ECList = XbEnterpriseBPM.SelectView_Enterprise_AccountList(SearchStr2.ToArray(), "NickName,EnterpriseId,Name", "CreationDate DESC", 6, 0, "ID");
50 StringBuilder Sb2 = new StringBuilder();
51 for (int i = 0; i < 6 && i < ECList.Count; i++)
52 {
53 Sb2.Append("<p><a href=\"http://light.xband.cn/eStore/Index.aspx?CorpID=" + ECList[i].EnterpriseID + "\">" + (ECList[i].Name.Length > 15 ? ECList[i].Name.Substring(0, 15) : ECList[i].Name) + "</a></p>");
54 }
55 Cache.Insert("ZXJM", Sb2.ToString(), null, DateTime.Now.AddMinutes(5), TimeSpan.Zero);
56 }
57 catch (Exception ex)
58 {
59 Cache.Insert("ZXJM", ex.Message, null, DateTime.Now.AddMinutes(5), TimeSpan.Zero);
60 }
61 finally
62 {
63 Response.Write(Cache["ZXJM"].ToString());
64 }
65 }
66 else {
67 Response.Write(Cache["ZXJM"].ToString());
68 }
69 break;
70 //默认无返回
71 default:
72 break;
73 }
74 }
75 }
76 }
注意前台页面需要清除所有代码只保留@Page行,如
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GetData.aspx.cs" Inherits="dealer_GetData" %>
2:异步JavaScript
Code
1 // JScript 文件
2 function startHTTP(id)
3 {
4 var xmlhttp;
5 if(window.ActiveXObject)
6 {
7 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
8 }
9 else if(window.XMLHttpRequest)
10 {
11 xmlhttp=new XMLHttpRequest();
12 }
13 xmlhttp.onreadystatechange=function(){
14 if(xmlhttp.readystate==4)//判断是否是完成状态
15 {
16 if(xmlhttp.status==200)//判断是否执行成功
17 {
18 document.getElementById(id).innerHTML=xmlhttp.responsetext;
19 }
20 }
21 };
22 xmlhttp.open("GET","GetData.aspx?type="+id,true);
23 xmlhttp.send(null);
24 }
25
1 // JScript 文件
2 function startHTTP(id)
3 {
4 var xmlhttp;
5 if(window.ActiveXObject)
6 {
7 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
8 }
9 else if(window.XMLHttpRequest)
10 {
11 xmlhttp=new XMLHttpRequest();
12 }
13 xmlhttp.onreadystatechange=function(){
14 if(xmlhttp.readystate==4)//判断是否是完成状态
15 {
16 if(xmlhttp.status==200)//判断是否执行成功
17 {
18 document.getElementById(id).innerHTML=xmlhttp.responsetext;
19 }
20 }
21 };
22 xmlhttp.open("GET","GetData.aspx?type="+id,true);
23 xmlhttp.send(null);
24 }
25
3:前台引用代码
Code
<div class="week_top10_con" id="ZXQG">
<script language="javascript" type="text/javascript">startHTTP('ZXQG')</script>
</div>
<div class="week_top10_con" id="ZXQG">
<script language="javascript" type="text/javascript">startHTTP('ZXQG')</script>
</div>
前台调需要注意的是,DIV的ID与调用时的参数需保持一致