实现效果:
前台放一个div用于显示幻灯片:
<div id="slideimg" ></div>
JS:
var focus_width=277 /*幻灯片新闻图片宽度*/ var focus_height=200 /*幻灯片新闻图片高度*/ var text_height=20 /*幻灯片新闻文字标题高度*/ var swf_height = focus_height+text_height var pics = ''; var links = ''; var texts = ''; function ati(url, img, title) { if(pics != '') { pics = pics+"|"; links = links+"|"; texts = texts+"|"; } pics = pics+escape(img); links = links+escape(url); texts = texts+title; } $(function(){ $.ajax({ url: 'JS/JumpImg.ashx', type: 'get', async:false,//阻塞方式,让数据调用完才加载图片 dataType: "json",/*这句可用可不用,没有影响*/ contentType: "application/json; charset=utf-8", success: function(result){ $.each( result, function (i, o) { //json = "text:" + o.A_Title + ", url:" + o.A_Img; ati('/S_'+o.A_ID+".html", "/"+o.A_Img, o.A_Title); }); }, error: function(){alert('Img Error');} }); $("#slideimg").html('<embed src="flash/pixviewer2.swf" wmode="opaque" FlashVars="pics='+pics+'&links='+links+'&texts='+texts+'&borderwidth='+focus_width+'&borderheight='+focus_height+'&textheight='+text_height+'" menu="false" bgcolor="#ffffff" quality="high" width="'+ focus_width +'" height="'+ swf_height +'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash">'); })
ashx代码:
<%@ WebHandler Language="C#" Class="JumpImg" %> using System; using System.Web; using System.Data; using Web.Dal; using Newtonsoft.Json; using Newtonsoft.Json.Converters; public class JumpImg : IHttpHandler { public void ProcessRequest (HttpContext context) { DataTable dt = new ArticleServer().Get(0, 5, 21, 2, 0); string result = JSONHelper.DataTableToJSON(dt); context.Response.Write(result); context.Response.End(); } public bool IsReusable { get { return false; } } }
- 本文标题: Jquery异步调用实现图片切换效果
- 文章分类:【JQuery/JavaScript】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.