加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ajax请求

发布时间:2020-12-15 21:35:48 所属栏目:百科 来源:网络整理
导读:文件服务器上传案例 ajax请求响应 //上传图片到文件服务器 $('#file_upload').uploadify({ width: 80, height: 20, fileSizeLimit: '4MB', buttonText: "选择图片", fileTypeExts: '*.jpg;*.bmp;*.gif;*.png', auto: true, multi: false, swf: '../Plugins/u

文件服务器上传案例

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,
uploader: '../../VoteManage/ImportHandler.ashx?fileType=img',
onSelect: function (file) {
isUpload = false;
$("#showFileName").html(file.name);
$("#fileinfo").val("");
},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);
}
},errorString) {
$("#fileinfo").val("");
Common.tips(erorMsg);
},
onCancel: function () {
respone = true;
}
});

不作具体解释

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读