C#使用ajaxForm进行上传图片
<div class='imgOuter addImgBtn l_canshu' id='ImagePath1' value=''>
<img src="../Images/AddI.gif" id="imgg" alt="Alternate Text" />
<form action="@UploadURL" method="post" enctype="multipart/form-data" id="user_head_form11">
<input type="file" class="bbbb" id="qdctvfile11" name="qdctvfile" onchange="eventStart(this);" />
<input type="hidden" id="redirectUrl" name="redirectUrl" value="http://@(System.Configuration.ConfigurationManager.AppSettings["UrlHasPort"])/CommonData/Callback" />
<input type="hidden" id="hidImg1" value="@Model.themePicUrl" />
<input type="hidden" name="type" value="" />
</form>
<dd class="cccc" id="cccc1" style="display: none">上传中.....</dd>
</div>
.zImagesUploadBox {
width: 961px;
height: 110px;
padding: 15px 20px 0;
}
.imgOuter {
float: left;
position: relative;
width: 168px;
height: 108px;
border: 1px solid #ccc;
margin-right: 12px;
}
.imgOuter p.btnsBox {
display: none;
position: absolute;
left: -1px;
bottom: 7px;
width: 142px;
height: 26px;
padding: 0 14px;
z-index: 2;
}
.imgOuter p.btnsBox a.deleteBtn {
float: right;
width: 68px;
height: 26px;
background: url("../Images/z_addImagesBtn_02.gif") 0 bottom no-repeat;
}
.imgOuter p.btnsBox a.bigImg {
float: left;
width: 68px;
height: 26px;
background: url("../Images/z_addImagesBtn_02.gif") no-repeat;
}
.imgOuter p.mask {
display: none;
position: absolute;
left: -1px;
top: -1px;
width: 170px;
height: 110px;
background: #000;
opacity: 0.5;
filter: alpha(opacity=50);
z-index: 1;
}
.imgOuter img {
display: block;
}
input {
outline: none;
}
.addImgBtn {
float: left;
width: 160px;
height: 90px;
cursor: pointer;
opacity: 100; background-size: 100% auto;
}
.bbbb{
cursor: pointer;position: absolute;right: 0;top: 0;opacity: 0;filter:alpha(opacity=0);height: 90px;width: 160px;
}
.cccc {
position: absolute;
background: #000;
opacity: 0.5;
width: 160px;
height: 90px;
text-align: center; padding: 40px;
color: #fff;
}
.addImgLayer {
left: 2px;
top: -108px;
width: 175px;
position: relative;
display: none;
}
em {
left: 0px;
top: 5px;
font-style: normal;
position: absolute;
font-size: 14px;
line-height: 26px;
padding: 0 0 0 0;
}
.l_canshu div i{ position:absolute; right:5px; top:3px; width:14px; height:14px; background:url(../Scripts/addResource/img/l_InnercloseImg.png) no-repeat; z-index:999; cursor:pointer;}
function eventStart(obj) {
var fileLength = getFileSize(obj);
if (fileLength < 1.5 * 1024 * 1024) {
$("#user_head_form11").submit();
}
else {
bootbox.alert({
size: 'small',
message: "请上传1.5M以内的图片文件!",
title: "提示",
callback: function () {
}
})
return false;
}
}
function getFileSize(obj) {
var objValue = obj.value;
if (objValue == "") return;
var fileLenth = -1;
try {
//对于IE判断要上传的文件的大小
var fso = new ActiveXObject("Scripting.FileSystemObject");
fileLenth = parseInt(fso.getFile(objValue).size);
} catch (e) {
try {
//对于非IE获得要上传文件的大小
fileLenth = parseInt(obj.files[0].size);
} catch (e) {
fileLenth = -1;
}
}
return fileLenth;
}
$(document).ready(function () {
$("#user_head_form11").ajaxForm({
iframe: true,
beforeSerialize: function () {
var filepath = $("#qdctvfile11").val()
var extStart = filepath.lastIndexOf(".");
var ext = filepath.substring(extStart, filepath.length).toUpperCase();
if (ext != ".PNG" && ext != ".JPG") {
bootbox.alert({
size: 'small',
message: "图片仅支持png,jpg格式",
title: "提示",
callback: function () {
}
})
$("#qdctvfile11").val("");
return false;
}
//$("#cccc1").show();
$("#imgg").attr("src", "../Images/11.png");
$("#hiddenImg").val(1);
},
success: function (data) {
data = JSON.parse(data);
$("#hiddenImg").val("");
$("#cccc1").hide();
if (data.code == "OK") {
$("#ImagePath1").attr("value", "1");
$("#hidImg1").val(data.originalImgUrl);
$("#imgg").attr("src", data.thumpImgUrl);
$("#themePicMd5").val(data.md5Abstract);
}
}
});//end ajaxForm
});
使用ajaxForm上传图片可以直接上传到接口上没有必要用自己后台做为中转
C#使用ajaxForm进行上传图片的更多相关文章
- ajax上传图片 jquery插件 jquery.form.js 的方法 ajaxSubmit; AjaxForm与AjaxSubmit的差异
先引入脚本 这里最好是把jquery的脚本升级到1.7 <script src="js/jquery-1.7.js" type="text/javascript& ...
- 手机端上传图片及java后台接收和ajaxForm提交
有很多微信开发的项目在手机端需要传图片,但是又不想调用微信的上传图片接口,于是采取了如下做法: 使用ajaxForm提交文件所需js:jquery.form.js 页面代码: <%@ page ...
- C# AJAXform上传图片
前台: @{ Layout = null;} <!DOCTYPE html> <html><head> <meta name="vie ...
- 异步上传图片,光用jquery不行,得用jquery.form.js插件
异步上传图片,光用jquery不行,得用jquery.form.js插件,百度一下下载这个插件,加jquery,引入就可以了 <form id="postbackground" ...
- 基于ASP.Net +easyUI框架上传图片,实现图片上传,提交表单
<body> <link href="../../Easyui/themes/easyui.css" rel="stylesheet" typ ...
- 博客使用BOS上传图片
1.博客平台的选定 从大学开始做个人主页算起,最开始是使用html,CSSS写简单的页面,后面大学毕业之后接触到了WordPress,就开始用WordPress搭建网站.现在还维护着一个农村网站.ht ...
- nodejs利用ajax实现网页无刷新上传图片
nodejs利用ajax实现网页无刷新上传图片 标签(空格分隔): nodejs 通常情况下上传图片是要通过提交form表单来实现的,但是这又不可避免的产生了网页转. 利用ajax技术和FormDat ...
- -Android -线程池 批量上传图片 -附php接收代码
(出处:http://www.cnblogs.com/linguanh/) 目录: 1,前序 2,类特点 3,用法 4,java代码 5,php代码 1,前序 还是源于重构,看着之前为赶时间写着的碎片 ...
- iOS 原生HTTP POST请求上传图片
今天项目里做一个上传图片等个人信息的时候,使用了第三方AFNetworking - (AFHTTPRequestOperation *)POST:(NSString *)URLString param ...
随机推荐
- javascript选取文档元素
用指定的id属性 用指定的name属性 用指定的标签名字 用指定的CSS类 匹配指定的CSS选择器 通过ID选取元素 var section1 = document.getElementById(&q ...
- 每天一个linux命令--locate
linux下,不知道自己安装的程序放在哪里了,可以使用locate命令进行查找. [hongye@dev107 ~]$ locate activemq.xml /home/hongye/hongyeC ...
- C#遍历enum类型
对于enum类型: 使用foreach遍历enum类型的元素并填充combox foreach ( HatchStyle hs1 in Enum.GetValues(typeof(HatchStyle ...
- AdaBoost 和 Real Adaboost 总结
AdaBoost 和 Real Adaboost 总结 AdaBoost Real AdaBoost AdaBoost AdaBoost, Adaptive Boosting(自适应增强), 是一种集 ...
- unity 解析tmx 2
using UnityEngine; using System.Collections; using System.Collections.Generic; using System.IO; usin ...
- [转]crontab环境变量设置
原文连接:http://blog.csdn.net/zc02051126/article/details/20480289 come from http://www.360doc.com/conten ...
- STL 的运用 istringstream的运用
单词数 Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- javascript new function()
// 执行的func生成一个空对象,如果有return就会把生成的func对象抛弃function func() {} alert(temp instanceof func) function fun ...
- golang channel 用法转的
一.Golang并发基础理论 Golang在并发设计方面参考了C.A.R Hoare的CSP,即Communicating Sequential Processes并发模型理论.但就像John Gra ...
- Maching Learning 学习资料
A星(A*, A Star)算法详解 CSDN技术主题月----“深度学习”代码笔记专栏 UC Berkeley CS188 Intro to AI