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 ...
随机推荐
- section和article元素
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 由addOneMember引发的思考
addOneMember是一个方法,这个方法在两处地方重复了. 所以在修改页面的时候,发现修改了一处,如果是新手,肯定不会注意到另外一处有问题,他如果没有看清楚这个类到底整体怎样,那么他会犯的错误是就 ...
- Windows RC版、RTM版、OEM版、RTL版、VOL版的区别
Windows 版本号标识区别一览表: 版本缩写 版本全称 版本意义 Alpha版 Alpha 内部测试版,一般不会向外部发布,会有很多Bug,只供测试人员使用,如果您看到Alpha版本了,一般来讲对 ...
- ural 1250. Sea Burial
1250. Sea Burial Time limit: 1.0 secondMemory limit: 64 MB There is Archipelago in the middle of a s ...
- python 代码片段21
#coding=utf-8 @doco def foo(): pass ''' deco把foo函数拿过来,加上一些额外的功能再重新赋值给foo,如下 ''' foo=deco(foo) def lo ...
- (转)Array.prototype.slice.call自解
很多框架或者库里面都会有这句的使用,最多的还是通过Array.prototype.slice.call(arguments,0)把arguments这个伪数组转换为真正的数组.但为什么可以这么做,却一 ...
- OpenResy+Lua 利用百度识图 将图片地址解析成文字
LUA代码:(注:LUA里有一个调用百度识图的接口IP:123.125.115.189(stu.baidu.com),不知为什么我的虚拟机无法解析stu.baidu.com,所以我只能PING出IP来 ...
- Codeforces Round #251 (Div. 2) A - Devu, the Singer and Churu, the Joker
水题 #include <iostream> #include <vector> #include <algorithm> using namespace std; ...
- [题解+总结]动态规划大合集II
1.前言 大合集总共14道题,出自江哥之手(这就没什么好戏了),做得让人花枝乱颤.虽说大部分是NOIP难度,也有简单的几道题目,但是还是做的很辛苦,有几道题几乎没思路,下面一道道边看边分析一下. 2. ...
- 【POJ2104/2761】K-th Number
Description You are working for Macrohard company in data structures department. After failing your ...