页面上AJAX调用数据
<div class="section page9" data-page='9'> <div class="global-section-wrp media-news-wrp" style="background-image: url(images/page9_06.jpg);"> <div class="w1180"> <h4 class="global-page-title animated antInUp">媒体声音</h4> <!-- media-news-slide start --> <div class="media-news-slide"> <div class="news-slide-bd" > <ul id="MeVoice"> </ul> </div> <div class="news-slide-ctrl animated antInUp"> <a href="javascript: void(0)" class="ctrl slide-prev"></a> <a href="javascript: void(0)" class="ctrl slide-next"></a> </div> </div> <!-- media-news-slide end --> </div> </div> </div>
//媒体声音 var kindnum = 9; LoadVoice(9); function LoadVoice(kindnum) { $.ajax({ type: "post", dataType: "json", url: "/ashx/MediaVoice.ashx", data: { kindNum: kindnum }, success: function (data) { var table = data.data.Rows; var voiceAdd = ""; if (table.length > 0) { for (var i = 0; i < table.length; i++) { voiceAdd += "<li class=\"animated antInUp\">"; voiceAdd += "<div class=\"news-slide-inner\">"; voiceAdd += "<div class=\"news-list-content\">"; voiceAdd += "<div class=\"news-image\">"; voiceAdd += "<a class=\"image\"><img data-src=\"" + table[i]["c_picurl1"] + "\"></a>"; voiceAdd += "</div>"; voiceAdd += "<div class=\"news-bd\">"; voiceAdd += "<h5 class=\"news-title\"><a target=\"_blank\" title='" + table[i]["c_info_title"] + "' href=\"" + table[i]["a2"] + "\">" + table[i]["c_info_title"] + "</a></h5>"; voiceAdd += "<div class=\"news-desc\">" + table[i]["beizhu1"] + "</div>"; voiceAdd += "<a target=\"_blank\" href=\"" + table[i]["a2"] + "\" class=\"news-more\">查看详情</a>"; voiceAdd += "</div>"; voiceAdd += "</div>"; voiceAdd += "</div>"; voiceAdd += "</li>"; } $("#MeVoice").html(voiceAdd); }
<%@ WebHandler Language="C#" Class="MediaVoice" %> using System.Web; using Maticsoft.DBUtility; using System.Data; using System.Data.SqlClient; using MT.Business; using Solucky; public class MediaVoice : IHttpHandler { protected string kindNum = ""; //当前栏目 public void ProcessRequest (HttpContext context) { context.Response.ContentType = "application/json"; kindNum =PageValidate.SqlTextClear(context.Request["kindNum"]); try { string str= GetMeVoice(context); context.Response.Write("{\"data\":" + str + "}"); } catch (System.Exception ex) { throw; } } /// <summary> /// 媒体声音 /// </summary> public string GetMeVoice(HttpContext context) { string result = ""; string sql = "select id,a2,c_info_title,beizhu1,g_id,c_picurl1,c_kind_num from b_infos where c_kind_num=@kindNum and n_is_active=1 order by n_order desc,d_list_date desc,id desc"; SqlParameter[] sqlParams = { new SqlParameter("@kindNum",SqlDbType.NVarChar,20), }; sqlParams[0].Value = kindNum; DataTable dt = DbHelperSQL.Query(sql, sqlParams).Tables[0]; for (int i = 0; i < dt.Rows.Count; i++) { if (!string.IsNullOrEmpty(dt.Rows[i]["c_picurl1"] + "")) { dt.Rows[i]["c_picurl1"] = Constant.UploadDir + "s/" + dt.Rows[i]["g_id"] + "/" + dt.Rows[i]["c_picurl1"].ToString(); } } Json json = new Json(); string dtdata = json.Convert2Json(dt); return dtdata; } public bool IsReusable { get { return false; } } }
}, error: function () { alert("ajax error"); } }); }