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 ...
随机推荐
- vim 文本编辑器
vim 文件名:命令模式 i 编辑模式 :输入模式 vim +n 文件名:打开文件,将光标置于第N行首部 命令模式进入输入模式进行编辑: i 当前光标位置插入文本 I 在当前行行首插入文本 o 在光标 ...
- JS 一位数左边补零
- python多线程之threading、ThreadPoolExecutor.map
背景: 某个应用场景需要从数据库中取出几十万的数据时,需要对每个数据进行相应的操作.逐个数据处理过慢,于是考虑对数据进行分段线程处理: 方法一:使用threading模块 代码: # -*- codi ...
- Java函数优雅之道
https://www.cnblogs.com/amap_tech/p/11320171.html 导读 随着软件项目代码的日积月累,系统维护成本变得越来越高,是所有软件团队面临的共同问题.持续地优化 ...
- 学习-Pytest(五)yield操作
1.fixture的teardown操作并不是独立的函数,用yield关键字呼唤teardown操作 2.scope="module" 1.fixture参数scope=”modu ...
- django笔记三之admin的管理
django笔记三之admin的管理 设置自动admin应用 vim todos/settings.py INSTALLED_APPS = ( 'django.contrib.admin', 新版本已 ...
- web框架-(六)Django补充---form表单验证
一.form表单验证 1. 常规html页面的form表单验证 常规页面中,如果想实现对表单中用户输入信息的数据验证,需要配合Ajax来实现. 使用前我们先来熟悉下函数参数:request,其中包含的 ...
- python中对RSA的加密和解密
首先,生成一对密钥,并保存 def create_keys(): # 生成公钥和私钥 (pubkey, privkey) = rsa.newkeys(1024) pub = pubkey.save_p ...
- DevExpress Winforms Controls:安装使用系统要求文档
[DevExpress WinForms v19.1下载] 本文档包含了有关安装和使用DevExpress WinForms控件的系统要求信息. .NET Framework 下图展示了支持的.NET ...
- 新建的COM组件中没有 MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
创建ATL组件之后,添加简单ATL对象,添加对话框资源,随后发现没有m_hWnd句柄,不响应初始化函数. 于是重新创建ATL组件,之后添加ATL控件,添加对话框资源,有m_hWnd句柄,但仍然不响应初 ...