jQuery file upload上传图片出错分析
以https://github.com/blueimp/jQuery-File-Upload/blob/master/basic-plus.html为例
注释掉load-image.all.min.js
<!--script src="//blueimp.github.io/JavaScript-Load-Image/js/load-image.all.min.js"></script-->
jquery.fileupload-image.js:279 Uncaught TypeError: Cannot read property 'parseMetaData' of undefined
at $.<computed>.<computed>.loadImageMetaData (jquery.fileupload-image.js:279)
at $.<computed>.<computed>.func (jquery.fileupload-process.js:84)
at $.<computed>.<computed>.<anonymous> (jquery.js:3305)
at fire (jquery.js:3148)
at Object.add [as done] (jquery.js:3194)
at Array.<anonymous> (jquery.js:3304)
at Function.each (jquery.js:384)
at Object.<anonymous> (jquery.js:3301)
at Function.Deferred (jquery.js:3361)
at Object.then (jquery.js:3300)
jquery.fileupload-process.js:84
_processFile: function (data, originalData) {这个函数中
return that.processActions[settings.action].call(
that,
data,
settings
);
jquery.fileupload-process.js:153
_processFile函数,被process函数调用
// Processes the files given as files property of the data parameter,
// returns a Promise object that allows to bind callbacks:
process: function (data) {
$.each(data.files, function (index) {
var opts = index ? $.extend({}, options) : options,
func = function () {
if (data.errorThrown) {
return $.Deferred()
.rejectWith(that, [data]).promise();
}
return that._processFile(opts, data);
};
jquery.fileupload.js:217
// The add callback is invoked as soon as files are added to the fileupload
// widget (via file input selection, drag & drop, paste or add API call).
// If the singleFileUploads option is enabled, this callback will be
// called once for each file in the selection for XHR file uploads, else
// once for each file selection.
//
// The upload starts when the submit method is invoked on the data parameter.
// The data object contains a files property holding the added files
// and allows you to override plugin options as well as define ajax settings.
//
// Listeners for this callback can also be bound the following way:
// .bind('fileuploadadd', func);
//
// data.submit() returns a Promise object and allows to attach additional
// handlers using jQuery's Deferred callbacks:
// data.submit().done(func).fail(func).always(func);
add: function (e, data) {
if (e.isDefaultPrevented()) {
return false;
}
if (data.autoUpload || (data.autoUpload !== false &&
$(this).fileupload('option', 'autoUpload'))) {
data.process().done(function () {
data.submit();
});
}
},
先执行$(this).fileupload('option', 'autoUpload'),触发了jquery.ui.widget.js中的代码
var widget_uuid = 0,
widget_slice = Array.prototype.slice;
$.fn[ name ] = function( options ) {
//对三个变量进行赋值
var isMethodCall = typeof options === "string",
args = widget_slice.call( arguments, 1 ),
returnValue = this;
这里的name是fileupload,options是option
arguments有2个元素, 0:option, 1:autoUpload
args经过赋值之后是autoUpload
if ( isMethodCall ) {
this.each(function() {
var methodValue,
instance = $.data( this, fullName );
fullName是blueimp-fileupload
经过赋值后
data函数调用触发了jquery中的函数
data: function( elem, name, data ) {
return internalData( elem, name, data );
},
elem是id为fileupload的input控件
name是blueimp-fileupload
经过赋值后,instance是fileupload的一个对象,这个对象包含一些数组元素,比如option
if ( !$.isFunction( instance[options] ) || options.charAt( 0 ) === "_" ) {
return $.error( "no such method '" + options + "' for " + name + " widget instance" );
}
instance[options]是一个函数,这个函数是jquery.ui.widget.js中定义的,因为blueimp-fileupload扩展了,所以blueimp-fileupload也包含这么一个函数
option: function( key, value ) {
var options = key,
parts,
curOption,
i;
args经过赋值之后是autoUpload
methodValue = instance[ options ].apply( instance, args );
因为上面的apply调用只传递了一个参数autoUpload
option: function( key, value ) {
var options = key,
parts,
curOption,
i;
else {
if ( arguments.length === 1 ) {
return this.options[ key ] === undefined ? null : this.options[ key ];
}
返回的methodValue是false
jQuery file upload上传图片出错分析的更多相关文章
- jQuery file upload上传图片的流程
先触发_onChange[jquery.fileupload.js] _onChange: function (e) { var that = this, data = { fileInput: $( ...
- jQuery File Upload 插件 php代码分析
jquery file upload php代码分析首先进入构造方法 __construct() 再进入 initialize()因为我是post方式传的数据 在进入initialize()中的po ...
- jQuery File Upload done函数没有返回
最近在使用jQuery File Upload 上传图片时发现一个问题,发现done函数没有callback,经过一番折腾,找到问题原因,是由于dataType: ‘json’造成的,改为autoUp ...
- 用jQuery File Upload做的上传控件demo,支持同页面多个上传按钮
需求 有这么一个需求,一个form有多个文件要上传,但又不是传统的图片批量上传那种,是类似下图这种需求,一开始是用的swfupload做的上传,但是问题是如果有多个按钮的话,就要写很多重复的代码,于为 ...
- jQuery File Upload blueimp with struts2 简单试用
Official Site的话随便搜索就可以去了 另外新版PHP似乎都有问题 虽然图片都可以上传 但是response报错 我下载的是8.8.7木有问题 但是8.8.7版本结合修改main. ...
- jQuery File Upload 单页面多实例的实现
jQuery File Upload 的 GitHub 地址:https://github.com/blueimp/jQuery-File-Upload 插件描述:jQuery File Upload ...
- jQuery File Upload文件上传插件简单使用
前言 开发过程中有时候需要用户在前段上传图片信息,我们通常可以使用form标签设置enctype=”multipart/form-data” 属性上传图片,当我们点击submit按钮的时候,图片信息就 ...
- jquery file upload示例
原文链接:http://blog.csdn.net/qq_37936542/article/details/79258158 jquery file upload是一款实用的上传文件插件,项目中刚好用 ...
- jquery file upload + asp.net 异步多文件上传
百度了很久,国内一直 找不到 使用jquery file upload 插件 +asp.net 的相关代码 一开始使用 jquery uploadify ,一款基于 flash的插件,但是不支持 Sa ...
随机推荐
- 5.jQuery之栏切换
<style> * { margin: 0; padding: 0; } li { list-style-type: none; } .tab { width: 978px; margin ...
- 定义一个数组,并对这个数组进行动态初始化,使用sort方法进行排序后,再将数组中的元素倒置过来。
Sort方法,生序排序 package com.fs.array; import java.util.Arrays; public class ArraySort { public static vo ...
- redis之使用场景
随着数据量的增长,MySQL 已经满足不了大型互联网类应用的需求.因此,Redis 基于内存存储数据,可以极大的提高查询性能,对产品在架构上很好的补充.在某些场景下,可以充分的利用 Redis 的特性 ...
- 可以提升幸福感的js小技巧(上)
1. 类型强制转换 1.1 string强制转换为数字 可以用 *1来转化为数字(实际上是调用 .valueOf方法) 然后使用 Number.isNaN来判断是否为 NaN,或者使用 a!==a 来 ...
- Android判断是debug还是release模式
1.当有些功能不希望在release模式实现时,但是debug模式又需要的时候,就可以对当前版本模式进行判断.如是debug模式则日志输出级别设置为Level.DEBUG,release模式设置为Le ...
- 关于一个function abc() 内 return一个值, 或者多个值写法
1.想return一个值,选第一种写法 function abc(){ a = '我是adad' return a } console.log(abc) // ==> 这个是错的,不要这样写,经 ...
- Delphi 保留字
- Ubuntu16.04下安装httpd+svn+viewVC
一.安装httpd 1.下载httpd 网址:http://httpd.apache.org/download.cgi#apache24 下载这一条---Source: httpd-2.4.39.ta ...
- 22_2mybatis——CURD
1.CURD操作 第一步:创建maven工程并导入坐标 <?xml version="1.0" encoding="UTF-8"?> <pro ...
- tensorflow中张量_常量_变量_占位符
1.tensor 在tensorflow中,数据是被封装在tensor对象中的.tensor是张量的意思,即包含从0到任意维度的张量.常数是0维度的张量,向量是1维度的张量,矩阵是二维度的张量,以及还 ...