您的位置:首页 > 其它

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;

}

});

不作具体解释
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: