在本文中,我们将给您介绍关于在ionic中用ajaxfileupload.js插件上传文件的详细内容,此外,我们还将为您提供关于$.ajaxFileUploadisnotafunction,使用aja
在本文中,我们将给您介绍关于在ionic中用 ajaxfileupload.js 插件上传文件的详细内容,此外,我们还将为您提供关于$.ajaxFileUpload is not a function,使用ajaxfileupload.js时提交报错、$.ajaxFileUpload文件上传、.net mvc ajaxfileupload.js 上传文件、ajax-AjaxFileUpload实现ajax上传文件的知识。
本文目录一览:- 在ionic中用 ajaxfileupload.js 插件上传文件
- $.ajaxFileUpload is not a function,使用ajaxfileupload.js时提交报错
- $.ajaxFileUpload文件上传
- .net mvc ajaxfileupload.js 上传文件
- ajax-AjaxFileUpload实现ajax上传文件
在ionic中用 ajaxfileupload.js 插件上传文件
1、定义一个file表单,并隐藏
<div> <div>附件</div> <div> <buttonng-click="uploadFile()">上传照片</button> <input type="file" id="hiddenFileWidget" name="img"onchange="angular.element(this).scope().startUpload()"> </div> </div> <input type="hidden" ng-model="formData.filePath">
注意事项:
1)、file控件在angular中没有所谓的“ng-change”事件,因此,只能使用“原生事件”
2)、onchange="angular.element(this).scope().startUpload()"是将原生事件引入到对应的$scope链中。
2、逻辑controller(控制层)选择文件确认之后上传文件
//上传文件 $scope.uploadFile = function(){ $("#hiddenFileWidget").click(); }; //上传文件 action $scope.startUpload = function(){ tipService.loading("正在上传图片"); publicRepairservice.uploadFileAction($scope); };
备注:tipService.loading("正在上传图片") 的作用是弹出一个遮罩层,提示用户正在上传,并且防止图片没有上传完成就提交数据。
3、对应的服务service处理具体的接口,用户定义上传成功之后的回调函数
//上传文件 function uploadFileAction(__scope__){ var mysetting = { url : "/Repair/updateImg",fileElementId : "hiddenFileWidget",data: { "token":userInfoService.getUserKey()},"token":userInfoService.getUserKey(),//相当于java中try语句块的用法,这里data是你post后返回的结果,要与dataType类型匹配 success: function (data,status) { },//相当于java中catch语句块的用法 error: function (data,status,e) { tipService.loadingHide(); var responseData = eval('(' + data.responseXML.documentElement.innerText + ')'); // $("#psersonImage").attr("src",responseData.data.avatar); if(responseData.status == 1){ tipService.alert({ title:"提示!",template:responseData.msg,callback:function(){ if(__scope__.formData.filePath == "" || __scope__.formData.filePath == null || __scope__.formData.filePath == undefined){ __scope__.formData.filePath = responseData.data; }else{ __scope__.formData.filePath = __scope__.formData.filePath + "," +responseData.data; } } }); }else if(responseData.status == 999){ tipService.alert({ title:"提示!",callback:function(){ //window.location.href="/wap/tmpl/member/login.html"; } }); }else{ tipService.alert({ title:"提示!",callback:function(){ } }); } } }; publicService.uploadFile(mysetting); }
备注:tipService.loadingHide();是隐藏遮罩层,允许用户操作。
4、底层利用ajaxfileupload.js插件完成异步上传文件
/* * 上传图片 * */ function uploadFile(mysetting){ function startUpload(){ $.ajaxFileUpload({ url : WAP_CONfig.path+mysetting.url,//需要链接到服务器地址 secureuri : false,//是否使用安全方式 https fileElementId : mysetting.fileElementId,//文件选择框的id属性 dataType: 'json',//服务器返回的格式,可以是xml,默认还是用js最喜欢的json data: mysetting.data,success: mysetting.success,//相当于java中try语句块的用法,这里data是你post后返回的结果,要与dataType类型匹配 error: mysetting.error //相当于java中catch语句块的用法 }); } //检测参数 mysetting = mysetting || {}; var defaultSetting = { url : "/Repair/updateImg",data : "",fileElementId : "",success : function(){},error:function(){} }; //覆盖默认参数 mysetting = $.extend(defaultSetting,mysetting); startUpload(mysetting); }
自定义弹出层工具服务
/** * 查询条件服务 * */ angular.module('houseApp') .factory('tipService',["ApiService","WAP_CONfig","$ionicPopup","$ionicLoading",function(ApiService,WAP_CONfig,$ionicPopup,$ionicLoading) { /* * alert 弹出提示 * */ var promptPopupObj; function prompt(){ var mysetting = mysetting || {}; var defaultSetting = { template: '<input type="password" ng-model="data.wifi">',title: 'Enter Wi-Fi Password',subTitle: 'Please use normal things',scope: $scope,buttons: [ { text: 'Cancel' },{ text: '<b>Save</b>',type: 'button-positive',onTap: function(e) { if (!$scope.data.wifi) { //不允许用户关闭,除非他键入wifi密码 e.preventDefault(); } else { return $scope.data.wifi; } } },] }; mysetting = $.extend(defaultSetting,mysetting); promptPopupObj = $ionicPopup.show({ template: mysetting.template,title:mysetting.title,subTitle:mysetting.subTitle,scope: mysetting.scope,buttons: mysetting.buttons }); myPopup.then(function(res) { console.log('Tapped!',res); }); } /** * 一个确认对话框 */ var confirmPopupObj; function confirm(mysetting){ var mysetting = mysetting || {}; var defaultSetting = { title:"Don\'t eat that!",template:"It might taste good",sureCallback:function(){ },falseCallBack:function(){ } }; mysetting = $.extend(defaultSetting,mysetting); confirmPopupObj = $ionicPopup.confirm({ title: mysetting.title,template: mysetting.template }); confirmPopupObj.then(function(res) { if(res) { mysetting.sureCallback(); }else { mysetting.falseCallBack(); } }); } /* * 一个提示对话框 * */ var alertPopupObj; function alert(mysetting){ var mysetting = mysetting || {}; var defaultSetting = { title:"Don\'t eat that!",callback:function(){ } }; mysetting = $.extend(defaultSetting,mysetting); alertPopupObj = $ionicPopup.alert({ title: mysetting.title,template: mysetting.template }); alertPopupObj.then(function(res) { mysetting.callback(); }); } /* * 弹出加载信息 * */ function loading(content){ if(content == "" || content == undefined || content == null){ content = 'Loading...'; } $ionicLoading.show({ template : content }); } /* * 隐藏加载信息 * */ function loadingHide(){ $ionicLoading.hide(); } //返回service的功能 return { "loading":loading,"loadingHide":loadingHide,"alert":alert,"prompt":prompt,"confirm":confirm }; }]);
- 大小: 8.3 KB
- 查看图片附件
$.ajaxFileUpload is not a function,使用ajaxfileupload.js时提交报错
$.ajaxFileUpload is not a function,使用ajaxfileupload.js时提交报错,这是什么原因?$.ajaxFileUpload文件上传
使用ajaxFileUpload
- 需要jquery.js和ajaxFileUpload.js
$.ajaxFileUpload({ url:'fileUpload',//你处理上传文件的服务端 secureuri:false,fileElementId:'file',//input file的id dataType:"json",//返回结果 success: function (data){ },error:function(e){ } }
返回结果中有<pre>
标签的问题
在ajaxFileUpload.js中,将eval( "data = " + data );
替换为
data = jQuery.parseJSON(jQuery(data).text());
.net mvc ajaxfileupload.js 上传文件
网上搜的类似资料一大堆,能用没几个。这个是自己工作中用到的,特此记录。
(
本文章以下Js方法需要自己改写, 或者注释掉, 或者使用Console.log() 来查看执行步骤,
Loading(true, "拼命导入中..请稍后...");
$.download("../../TicketManage/SendGoods/DownLoadTemplate", ''post'');
dialogMsg(e, -1);
)
Util.Offices.ExcelHelper.ExcelToDt(stream); 使用Epplus把流转换成DataTable(代码下面贴出了)
----------------------------------------------------------------------------不华丽的代码分割线------------------------------------------------------------------------------------------
uploadForm.cshtml
@{
ViewBag.Title = "数据导入";
Layout = "~/Views/Shared/_Index.cshtml";
}
<script src="~/Content/scripts/plugins/ajaxfileupload/ajaxfileupload.js"></script>
<script>
$(function () {
$(''#uploadFile'').bind("change", function (e) {
//alert("a");
});
});
//开始导入
function btn_importdata() {
Loading(true, "拼命导入中..请稍后...");
$.ajaxFileUpload({
url: ''../../TicketManage/SendGoods/Import'',//后台请求地址
type: ''POST'',//请求方式 当要提交自定义参数时,这个参数要设置成post
secureuri: false,//是否启用安全提交,默认为false。
fileElementId: ''uploadFile'',// 需要上传的文件域的ID,即<input type="file">的ID。
dataType: ''json'',
success: function (data) {//提交成功后自动执行的处理函数,参数data就是服务器返回的数据。
$("#msg").html("");
var d = data.msg.split(''\n'');
if (data.state) {
$("#msg").attr("class", "alert alert-success").append(data.msg);
} else {
$("#msg").attr("class", "alert alert-danger");
for (var i = 0; i < d.length; i++) {
if (+d[i] != '''') {
$("#msg").append("<strong>警告!</strong>" + d[i] + "<br/>");
}
}
}
$("#uploadFile").val('''');//解决同名文件只发送一次请求的问题
$("#filetext").val('''');//友好提示文件名
Loading(false);
},
error: function (json, status, e) {//提交失败自动执行的处理函数。
dialogMsg(e, -1);
$("#msg").html(e);
// console.log(data);
$("#uploadFile").val('''');//解决同名文件只发送一次请求的问题
$("#filetext").val('''');//友好提示
Loading(false);
}
});
}
//设置显示
function onchange_ShowFile(e) {
var file = $("#uploadFile").val();
//var pos = file.lastIndexOf("\\");
//console.log(file);
$("#filetext").val(file);
//console.log(file.substring(pos + 1));
}
//选择文件
function btn_getimportdata() {
$("#uploadFile").trigger(''click'');
}
//下载模板
function btn_downLoadTempte() {
$.download("../../TicketManage/SendGoods/DownLoadTemplate", ''post'');
}
</script>
<div>
<div>
<div>
<input id="uploadFile" name="uploadFile" onchange="onchange_ShowFile()"type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" />
<input readonly type="text"id="filetext" />
<button id="choose"onclick="btn_getimportdata()"> <i></i> 选择</button>
<button id="lr-choose"onclick="btn_importdata()"><i></i> 开始导入</button>
<button id="lr-import"onclick="btn_downLoadTempte()"> <i></i> 下载模板</button>
</div>
<div id="tips">
<strong> 提示:</strong>1.下载模板文件并将相关数据正确填充 2.点击选择文件。3.点击开始导入。4.返回结果
</div>
<divid="msg">
<strong>返回结果:</strong>在这里看返回结果哦<br />
</div>
</div>
</div>
后台代码:
#region 导入数据
[HttpPost]
public ActionResult Import()
{
var files = Request.Files;
JsonResult json = new JsonResult
{
ContentType = "text/html",
};
var currentUser = OperatorProvider.Provider.Current();
if (files.Count > 0)
{
var stream = files[0].InputStream;
var name = files[0].FileName;
if (name.IsEmpty())
{
json.Data = new { state = false, msg = "请先选择文件" }; return json;
}
if (name.Length <= 4)
{
json.Data = new { state = false, msg = "文件格式不正确" }; return json;
}
if (name.Substring(name.Length - 4).ToUpper() != "XLSX")
{
json.Data = new { state = false, msg = "文件格式不正确,请使用xlsx文件" }; return json;
}
var dt = Util.Offices.ExcelHelper.ExcelToDt(stream);
List<DataRow> removelist = new List<DataRow>();
for (int i = 0; i < dt.Rows.Count; i++)
{
bool IsNull = true;
for (int j = 0; j < dt.Columns.Count; j++)
{
if (!string.IsNullOrEmpty(dt.Rows[i][j].ToString().Trim()))
{
IsNull = false;
}
}
if (IsNull)
{
removelist.Add(dt.Rows[i]);
}
}
for (int i = 0; i < removelist.Count; i++)
{
dt.Rows.Remove(removelist[i]);
}
if (dt.Rows.Count == 0)
{
json.Data = new { state = false, msg = "文件中无数据,请重新上传。" }; return json;
}
var res = sendgoodsbll.Import(dt);
json.Data = new { state = res.Item1, msg = res.Item2 };
return json;
}
else
{
json.Data = new { state = false, msg = "上传失败,无文件" }; return json;
}
}
[HttpPost]
public void DownLoadTemplate()
{
var fileName = Server.MapPath("~/Resource/Template/导入终端发货单模板.xlsx");
FileHelper.DownLoadold(fileName, "导入终端发货单模板.xlsx");
}
#endregion
把文件流转换成DataTable帮助类:
public static DataTable ExcelToDt(Stream stream)
{
ExcelPackage package = new ExcelPackage(stream);
ExcelWorksheet sheet = package.Workbook.Worksheets[1];
DataTable dt = new DataTable();
//for (int col = 0; col < sheet.Dimension.End.Column; col++)
//{
// dt.Columns.Add(col.ToString(), );
//}
foreach (var firstRowCell in sheet.Cells[1, 1, 1, sheet.Dimension.End.Column])
{
dt.Columns.Add(firstRowCell.Text, Type.GetType("System.String"));
}
int startRowIndx = sheet.Dimension.Start.Row + 1;//去掉列头
for (int r = startRowIndx; r <= sheet.Dimension.End.Row; r++)
{
DataRow dr = dt.NewRow();
for (int c = sheet.Dimension.Start.Column; c <= sheet.Dimension.End.Column; c++)
{
if (sheet.Cells[r, c].Style.Numberformat.Format.IndexOf("yyyy") > -1
&& sheet.Cells[r, c].Value != null)//注意这里,是处理日期时间格式的关键代码
{
dr[c - 1] = sheet.Cells[r, c].GetValue<DateTime>();
}
else
dr[c - 1] = (sheet.Cells[r, c].Value ?? DBNull.Value)?.ToString()?.Trim();
}
dt.Rows.Add(dr);
}
return dt;
}
本人修改后的ajaxfileupload.js文件
jQuery.extend({
createUploadIframe: function (id, uri) {
//create frame
var frameId = ''jUploadFrame'' + id;
var iframeHtml = ''<iframe id="'' + frameId + ''" name="'' + frameId + ''"'';
if (window.ActiveXObject) {
if (typeof uri == ''boolean'') {
iframeHtml += '' src="'' + ''javascript:false'' + ''"'';
}
else if (typeof uri == ''string'') {
iframeHtml += '' src="'' + uri + ''"'';
}
}
iframeHtml += '' />'';
jQuery(iframeHtml).appendTo(document.body);
return jQuery(''#'' + frameId).get(0);
},
createUploadForm: function (id, fileElementId, data) {
//create form
var formId = ''jUploadForm'' + id;
var fileId = ''jUploadFile'' + id;
var $form = jQuery(''<form action="" method="POST" name="'' + formId + ''" id="'' + formId + ''" enctype="multipart/form-data"></form>'');
if (data) {
for (var i in data) {
jQuery("<input type=''hidden'' name=''" + i + "'' value=''" + data[i] + "'' />").appendTo($form);
}
}
//console.log(data);
//console.log("基于官网的二次修改,作者:HandLoong");
var oldElement = jQuery(''#'' + fileElementId);
var newElement = jQuery(oldElement).clone();
jQuery(oldElement).attr(''id'', fileId);
jQuery(oldElement).before(newElement);
jQuery(oldElement).appendTo($form);
//var form = jQuery.createUploadForm(id, s.fileElementId, s.data);
//set attributes
$form.css(''position'', ''absolute'');
$form.css(''top'', ''-1200px'');
$form.css(''left'', ''-1200px'');
$form.appendTo(''body'');
//console.log("创建一个from");
return $form;
},
ajaxFileUpload: function (s) {
// TODO introduce global settings, allowing the client to modify them for all requests, not only timeout
s = jQuery.extend({}, jQuery.ajaxSettings, s);
var id = new Date().getTime()
var $form = jQuery.createUploadForm(id, s.fileElementId, (typeof (s.data) == ''undefined'' ? false : s.data));
var io = jQuery.createUploadIframe(id, s.secureuri);
var frameId = ''jUploadFrame'' + id;
var formId = ''jUploadForm'' + id;
// Watch for a new set of requests
if (s.global && !jQuery.active++) {
jQuery.event.trigger("ajaxStart");
}
var requestDone = false;
// Create the request object
var xml = {}
if (s.global)
jQuery.event.trigger("ajaxSend", [xml, s]);
// Wait for a response to come back
var uploadCallback = function (isTimeout) {
var io = document.getElementById(frameId);
try {
if (io.contentWindow) {
xml.responseText = io.contentWindow.document.body ? io.contentWindow.document.body.innerHTML : null;
xml.responseXML = io.contentWindow.document.XMLDocument ? io.contentWindow.document.XMLDocument : io.contentWindow.document;
} else if (io.contentDocument) {
xml.responseText = io.contentDocument.document.body ? io.contentDocument.document.body.innerHTML : null;
xml.responseXML = io.contentDocument.document.XMLDocument ? io.contentDocument.document.XMLDocument : io.contentDocument.document;
}
} catch (e) {
jQuery.handleError(s, xml, null, e);
}
if (xml || isTimeout == "timeout") {
requestDone = true;
var status;
try {
status = isTimeout != "timeout" ? "success" : "error";
// Make sure that the request was successful or notmodified
if (status != "error") {
// process the data (runs the xml through httpData regardless of callback)
var data = jQuery.uploadHttpData(xml, s.dataType);
// If a local callback was specified, fire it and pass it the data
if (s.success)
s.success(data, status);
// Fire the global callback
if (s.global)
jQuery.event.trigger("ajaxSuccess", [xml, s]);
} else
jQuery.handleError(s, xml, status);
} catch (e) {
status = "error";
jQuery.handleError(s, xml, status, e);
}
// The request was completed
if (s.global)
jQuery.event.trigger("ajaxComplete", [xml, s]);
// Handle the global AJAX counter
if (s.global && ! --jQuery.active)
jQuery.event.trigger("ajaxStop");
// Process result
if (s.complete)
s.complete(xml, status);
jQuery(io).unbind()
setTimeout(function () {
try {
jQuery(io).remove();
jQuery(form).remove();
} catch (e) {
jQuery.handleError(s, xml, null, e);
}
}, 100)
xml = null
}
}
// Timeout checker
if (s.timeout > 0) {
setTimeout(function () {
// Check to see if the request is still happening
if (!requestDone) uploadCallback("timeout");
}, s.timeout);
}
try {
//var form = jQuery(''#'' + formId);
$form.attr(''action'', s.url);
$form.attr(''method'', ''POST'');
$form.attr(''target'', frameId);
if ($form.encoding) {
$form.attr(''encoding'', ''multipart/form-data'');
}
else {
$form.attr(''enctype'', ''multipart/form-data'');
}
console.log($form);
$form.submit();
} catch (e) {
jQuery.handleError(s, xml, null, e);
}
jQuery(''#'' + frameId).load(uploadCallback);
return { abort: function () { } };
},
uploadHttpData: function (r, type) {
var data = !type;
data = type == "xml" || data ? r.responseXML : r.responseText;
// If the type is "script", eval it in global context
if (type == "script")
jQuery.globalEval(data);
// Get the JavaScript object, if JSON is used.
if (type == "json")
eval("data = " + data);
// evaluate scripts within html
if (type == "html")
jQuery("<div>").html(data).evalScripts();
return data;
},
handleError: function (s, xhr, status, e) {
// If a local callback was specified, fire it
if (s.error) {
s.error.call(s.context || s, xhr, status, e);
}
// Fire the global callback
if (s.global) {
(s.context ? jQuery(s.context) : jQuery.event).trigger("ajaxError", [xhr, s, e]);
}
}
})
最后结果:
ajax-AjaxFileUpload实现ajax上传文件
一.参考文件
1.AjaxFileUpload github官网
二.场景
1.前端上传通过 input file标签上传文件到后端,可以用表单做,但是用ajax时不太方便,所以用这个query插件比较好。
三.举个栗子
$("#uploadButton").click(function () {
$.ajaxFileUpload({
url: uploadFileUrl,
type: ''POST'',
fileElementId: ''file'',//file input的id
dataType: ''json'',//这里我改成大写后出现了乱码情况,小写不会
cache: false,
enctype: "multipart/form-data",
traditional: true,
success: function (data) {
if (data != null) {
alert("创建成功");
}
},
});
})
四.后端的处理可结合以下博客(SpringMvc)
https://my.oschina.net/Cubicluo/blog/894776
四.附件:以下是源码(仅供参考,这里只是摘录),只是做个备份,请去官网下载。
jQuery.extend({
createUploadIframe: function(id, uri)
{
//create frame
var frameId = ''jUploadFrame'' + id;
if(window.ActiveXObject) {
var io = document.createElement(''<iframe id="'' + frameId + ''" name="'' + frameId + ''" />'');
if(typeof uri== ''boolean''){
io.src = ''javascript:false'';
}
else if(typeof uri== ''string''){
io.src = uri;
}
}
else {
var io = document.createElement(''iframe'');
io.id = frameId;
io.name = frameId;
}
io.style.position = ''absolute'';
io.style.top = ''-1000px'';
io.style.left = ''-1000px'';
document.body.appendChild(io);
return io
},
createUploadForm: function(id, fileElementId)
{
//create form
var formId = ''jUploadForm'' + id;
var fileId = ''jUploadFile'' + id;
var form = $(''<form action="" method="POST" name="'' + formId + ''" id="'' + formId + ''" enctype="multipart/form-data"></form>'');
var oldElement = $(''#'' + fileElementId);
var newElement = $(oldElement).clone();
$(oldElement).attr(''id'', fileId);
$(oldElement).before(newElement);
$(oldElement).appendTo(form);
//set attributes
$(form).css(''position'', ''absolute'');
$(form).css(''top'', ''-1200px'');
$(form).css(''left'', ''-1200px'');
$(form).appendTo(''body'');
return form;
},
addOtherRequestsToForm: function(form,data)
{
// add extra parameter
var originalElement = $(''<input type="hidden" name="" value="">'');
for (var key in data) {
name = key;
value = data[key];
var cloneElement = originalElement.clone();
cloneElement.attr({''name'':name,''value'':value});
$(cloneElement).appendTo(form);
}
return form;
},
ajaxFileUpload: function(s) {
// TODO introduce global settings, allowing the client to modify them for all requests, not only timeout
s = jQuery.extend({}, jQuery.ajaxSettings, s);
var id = new Date().getTime()
var form = jQuery.createUploadForm(id, s.fileElementId);
if ( s.data ) form = jQuery.addOtherRequestsToForm(form,s.data);
var io = jQuery.createUploadIframe(id, s.secureuri);
var frameId = ''jUploadFrame'' + id;
var formId = ''jUploadForm'' + id;
// Watch for a new set of requests
if ( s.global && ! jQuery.active++ )
{
jQuery.event.trigger( "ajaxStart" );
}
var requestDone = false;
// Create the request object
var xml = {}
if ( s.global )
jQuery.event.trigger("ajaxSend", [xml, s]);
// Wait for a response to come back
var uploadCallback = function(isTimeout)
{
var io = document.getElementById(frameId);
try
{
if(io.contentWindow)
{
xml.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;
xml.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document;
}else if(io.contentDocument)
{
xml.responseText = io.contentDocument.document.body?io.contentDocument.document.body.innerHTML:null;
xml.responseXML = io.contentDocument.document.XMLDocument?io.contentDocument.document.XMLDocument:io.contentDocument.document;
}
}catch(e)
{
jQuery.handleError(s, xml, null, e);
}
if ( xml || isTimeout == "timeout")
{
requestDone = true;
var status;
try {
status = isTimeout != "timeout" ? "success" : "error";
// Make sure that the request was successful or notmodified
if ( status != "error" )
{
// process the data (runs the xml through httpData regardless of callback)
var data = jQuery.uploadHttpData( xml, s.dataType );
// If a local callback was specified, fire it and pass it the data
if ( s.success )
s.success( data, status );
// Fire the global callback
if( s.global )
jQuery.event.trigger( "ajaxSuccess", [xml, s] );
} else
jQuery.handleError(s, xml, status);
} catch(e)
{
status = "error";
jQuery.handleError(s, xml, status, e);
}
// The request was completed
if( s.global )
jQuery.event.trigger( "ajaxComplete", [xml, s] );
// Handle the global AJAX counter
if ( s.global && ! --jQuery.active )
jQuery.event.trigger( "ajaxStop" );
// Process result
if ( s.complete )
s.complete(xml, status);
jQuery(io).unbind()
setTimeout(function()
{ try
{
$(io).remove();
$(form).remove();
} catch(e)
{
jQuery.handleError(s, xml, null, e);
}
}, 100)
xml = null
}
}
// Timeout checker
if ( s.timeout > 0 )
{
setTimeout(function(){
// Check to see if the request is still happening
if( !requestDone ) uploadCallback( "timeout" );
}, s.timeout);
}
try
{
// var io = $(''#'' + frameId);
var form = $(''#'' + formId);
$(form).attr(''action'', s.url);
$(form).attr(''method'', ''POST'');
$(form).attr(''target'', frameId);
if(form.encoding)
{
form.encoding = ''multipart/form-data'';
}
else
{
form.enctype = ''multipart/form-data'';
}
$(form).submit();
} catch(e)
{
jQuery.handleError(s, xml, null, e);
}
if(window.attachEvent){
document.getElementById(frameId).attachEvent(''onload'', uploadCallback);
}
else{
document.getElementById(frameId).addEventListener(''load'', uploadCallback, false);
}
return {abort: function () {}};
},
uploadHttpData: function( r, type ) {
var data = !type;
data = type == "xml" || data ? r.responseXML : r.responseText;
// If the type is "script", eval it in global context
if ( type == "script" )
jQuery.globalEval( data );
// Get the JavaScript object, if JSON is used.
if ( type == "json" )
{
// If you add mimetype in your response,
// you have to delete the ''<pre></pre>'' tag.
// The pre tag in Chrome has attribute, so have to use regex to remove
var data = r.responseText;
var rx = new RegExp("<pre.*?>(.*?)</pre>","i");
var am = rx.exec(data);
//this is the desired data extracted
var data = (am) ? am[1] : ""; //the only submatch or empty
eval( "data = " + data );
}
// evaluate scripts within html
if ( type == "html" )
jQuery("<div>").html(data).evalScripts();
//alert($(''param'', data).each(function(){alert($(this).attr(''value''));}));
return data;
}
})
今天的关于在ionic中用 ajaxfileupload.js 插件上传文件的分享已经结束,谢谢您的关注,如果想了解更多关于$.ajaxFileUpload is not a function,使用ajaxfileupload.js时提交报错、$.ajaxFileUpload文件上传、.net mvc ajaxfileupload.js 上传文件、ajax-AjaxFileUpload实现ajax上传文件的相关知识,请在本站进行查询。
本文标签: