Ajax异步无刷新显示图片


前台:

 

// 图片
var path = '<%= ResolveUrl("~/Img/") %>';
var imgUrl = path +  "/" + result.FileName.substr(result.FileName.lastIndexOf('/') + 1);
var img = new Image();
img.src = imgUrl;
 

if (!img.complete) {

//无图片
}
else //有图片
{
    if (img.width < 500) { // 小于最大宽度,按实际宽度显示
     $("#<%=Image1.ClientID %>").css("width", img.width);
     }
     else { // 大于等于最大宽度,按最大宽度显示
    $("#<%=Image1.ClientID %>").css("width", 500);
     }
}

后台初始化获取第一张图片:

System.Drawing.Image imgPhoto = System.Drawing.Image.FromFile(Server.MapPath(url));
int sourceWidth = imgPhoto.Width;
int sourceHeight = imgPhoto.Height;
 
if (sourceWidth < 500)
{
Unit width = new Unit(sourceWidth);
this.Image1.Width = width;
}
if (sourceHeight < 350)
{
Unit height = new Unit(sourceHeight);
this.Image1.Height = height;
}

ashx文件获取切换的图片数据(使用json返回):

 

JavaScriptSerializer serializer = new JavaScriptSerializer();
string jsonStr = serializer.Serialize(model);
 
context.Response.Write(jsonStr);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM