Ajax异步无刷新显示图片
2012-03-11 12:50
936 查看
前台:
//图片
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);
//图片
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);
相关文章推荐
- 使用SpringMvc跨服务器上传图片,Ajax异步刷新图片框显示图片功能请求不到后台,onChange事件没有激活的源码?
- javaweb局部刷新-ajax异步请求springMVC显示返回的jsp内容,代替iframe
- jquery的ajax异步请求上传完图片之后会有页面跳转和刷新如何解决?
- jQuery插件之ajaxFileUpload(异步上传图片并实时显示,并解决onchange后ajaxFileUpload失效问题)
- Thinkphp3.2.3验证码的显示、点击刷新、ajax异步验证
- ajax异步调用,当鼠标点在图片上时,显示一个新层读取数据内容
- 权限管理页面,ajax异步刷新,获取当前用户权限-checkbox显示已选
- ajax异步上传图片并显示
- php下使用ajax异步上传图片并显示缩略图
- jQuery插件之ajaxFileUpload(异步上传图片并实时显示,并解决onchange后ajaxFileUpload失效问题)
- jQuery插件之ajaxFileUpload(异步上传图片并实时显示,并解决onchange后ajaxFileUpload失效问题)
- jQuery插件之ajaxFileUpload(异步上传图片并实时显示,并解决onchange后ajaxFileUpload失效问题)
- jQuery插件之ajaxFileUpload(异步上传图片并实时显示,并解决onchange后ajaxFileUpload失效问题)
- Ajax异步刷新将毫秒数时间格式化显示
- Jquery ajaxsubmit 异步上传图片 无刷新
- android ImageView 异步下载显示图片
- 导航栏 $_ajax异步局部刷新加载内容
- 定时请求php 后台 AJAX 请求,在页面中倒计时,和显示刷新时间
- 使用FormData进行Ajax请求异步上传图片案例
- ajax 异步加载显示等待效果