ajax请求
2016-01-21 10:43
183 查看
文件服务器上传案例
ajax请求响应
//上传图片到文件服务器
$('#file_upload').uploadify({
width: 80,
height: 20,
fileSizeLimit: '4MB',
buttonText: "选择图片",
fileTypeExts: '*.jpg;*.bmp;*.gif;*.png',
auto: true,
multi: false,
swf: '../Plugins/uploadify/uploadify.swf',
uploader: Constant.file_Url + 'UploadHandler.ashx',
onSelect: function (file) {
$("#showFileName").html(file.name);
},
onUploadSuccess: function (file, data, respone) {
if (respone) {
data = eval("(" + data + ")");
if (data.Success) {
$("#fileinfo").val(data.Data.ID);
}
}
},
onUploadError: function (file, errorCode, erorMsg, errorString) {
$("#fileinfo").val("");
Common.tips(erorMsg);
}
});
其中
onSelect 选择执行的事件
onUploadSuccess 上传成功之后执行的事件
文件服务器代码稍后上传(由于公司内部保密 不上传一些敏感的信息)
Constant.code_Url 需要请求的地址
uploader: Constant.file_Url + 'UploadHandler.ashx',
这个在我们自己的文件服务器上是上传你的临时文件
需要 确认
$.ajax({
url: Constant.file_Url + "ConfirmHandler.ashx",
data: { t: $.toJSON([info.fileID]) },
type: "POST",
dataType: 'jsonp',
success: function (result) {
var xx = result;
}
});
获取资源 上传视频预览 得到地址
//var picurl = Constant.file_Url + "/Preview.ashx";
var picurl = Constant.file_Url + "/GetFiles.ashx?FileID=" + param;
$.ajax({
type: "POST",
url: picurl,
data: { FileID: param },
dataType: "jsonp",
success: function (msg) {
msg = eval(msg)
if (msg.CanPreview) {
// alert(msg.URL);
// window.location.href = msg.URL;
var tempHtmlUpdate = $("#div_AddVote")[0];
art.dialog({
content: tempHtmlUpdate,
title: '预览',
lock: true,
ok: function () {
},
cancelVal: '取消',
cancel: true //为true等价于function(){}
});
$("#div_AddVote").html("<iframe width=500 height=500 src=" + msg.URL + "></iframe>");
}
},
error: function (e, x) {
}
});
下面这个是
这个是上传到本地的
//上传图片到本地
var isUpload = true;
$('#file_upload').uploadify({
width: 80,
height: 20,
fileSizeLimit: '4MB',
buttonText: "选择图片",
fileTypeExts: '*.jpg;*.bmp;*.gif;*.png',
auto: true,
multi: false,
swf: '../Plugins/uploadify/uploadify.swf',
uploader: '../../VoteManage/ImportHandler.ashx?fileType=img',
onSelect: function (file) {
isUpload = false;
$("#showFileName").html(file.name);
$("#fileinfo").val("");
},
onUploadSuccess: function (file, data, respone) {
if (respone) {
isUpload = true;
var newdata = data.replace(/\\/g, "/");
var num = newdata.indexOf("/Upload", 0)
var uploadPath = newdata.substring(num, newdata.length);
$("#fileinfo").val(uploadPath);
}
},
onUploadError: function (file, errorCode, erorMsg, errorString) {
$("#fileinfo").val("");
Common.tips(erorMsg);
},
onCancel: function () {
respone = true;
}
});
不作具体解释
ajax请求响应
//上传图片到文件服务器
$('#file_upload').uploadify({
width: 80,
height: 20,
fileSizeLimit: '4MB',
buttonText: "选择图片",
fileTypeExts: '*.jpg;*.bmp;*.gif;*.png',
auto: true,
multi: false,
swf: '../Plugins/uploadify/uploadify.swf',
uploader: Constant.file_Url + 'UploadHandler.ashx',
onSelect: function (file) {
$("#showFileName").html(file.name);
},
onUploadSuccess: function (file, data, respone) {
if (respone) {
data = eval("(" + data + ")");
if (data.Success) {
$("#fileinfo").val(data.Data.ID);
}
}
},
onUploadError: function (file, errorCode, erorMsg, errorString) {
$("#fileinfo").val("");
Common.tips(erorMsg);
}
});
其中
onSelect 选择执行的事件
onUploadSuccess 上传成功之后执行的事件
文件服务器代码稍后上传(由于公司内部保密 不上传一些敏感的信息)
Constant.code_Url 需要请求的地址
uploader: Constant.file_Url + 'UploadHandler.ashx',
这个在我们自己的文件服务器上是上传你的临时文件
需要 确认
$.ajax({
url: Constant.file_Url + "ConfirmHandler.ashx",
data: { t: $.toJSON([info.fileID]) },
type: "POST",
dataType: 'jsonp',
success: function (result) {
var xx = result;
}
});
获取资源 上传视频预览 得到地址
//var picurl = Constant.file_Url + "/Preview.ashx";
var picurl = Constant.file_Url + "/GetFiles.ashx?FileID=" + param;
$.ajax({
type: "POST",
url: picurl,
data: { FileID: param },
dataType: "jsonp",
success: function (msg) {
msg = eval(msg)
if (msg.CanPreview) {
// alert(msg.URL);
// window.location.href = msg.URL;
var tempHtmlUpdate = $("#div_AddVote")[0];
art.dialog({
content: tempHtmlUpdate,
title: '预览',
lock: true,
ok: function () {
},
cancelVal: '取消',
cancel: true //为true等价于function(){}
});
$("#div_AddVote").html("<iframe width=500 height=500 src=" + msg.URL + "></iframe>");
}
},
error: function (e, x) {
}
});
下面这个是
这个是上传到本地的
//上传图片到本地
var isUpload = true;
$('#file_upload').uploadify({
width: 80,
height: 20,
fileSizeLimit: '4MB',
buttonText: "选择图片",
fileTypeExts: '*.jpg;*.bmp;*.gif;*.png',
auto: true,
multi: false,
swf: '../Plugins/uploadify/uploadify.swf',
uploader: '../../VoteManage/ImportHandler.ashx?fileType=img',
onSelect: function (file) {
isUpload = false;
$("#showFileName").html(file.name);
$("#fileinfo").val("");
},
onUploadSuccess: function (file, data, respone) {
if (respone) {
isUpload = true;
var newdata = data.replace(/\\/g, "/");
var num = newdata.indexOf("/Upload", 0)
var uploadPath = newdata.substring(num, newdata.length);
$("#fileinfo").val(uploadPath);
}
},
onUploadError: function (file, errorCode, erorMsg, errorString) {
$("#fileinfo").val("");
Common.tips(erorMsg);
},
onCancel: function () {
respone = true;
}
});
不作具体解释
相关文章推荐
- 百度云播放视频尺寸加大的方法
- Ubuntu14.04 创建应用图标
- IOS NSString类字符串拼接与截取注意点
- Ugly Number II
- 关于烂代码的那些事(上)
- viewPager的简单使用
- 系统最大连接数
- Caused by: android.util.AndroidRuntimeException: Calling startActivity() from outside of an Activity
- Android——systembroadcast 列表
- Android——permission 列表
- centos apache IE8兼容
- nodejs学习笔记<安装和配置>
- Java中方法的重载与覆写的区别
- Jquery三级菜单切换
- webstorm 设置jsp支持ZenCoding
- 【转】VS2010发布、打包安装程序(超全超详细)
- symfony配置
- 【老生常谈】Attr与Prop的区别
- html 选择图片后马上展示出来
- 谈谈C#中的内存分配