ajaxSubmit提交文件表单不执行success
先描述一下我遇到的问题,系统里所有的表单都用ajaxSubmit来提交,成功回调success函数,普通表单都是没有问题的,但是有文件上传的表单就不行了,不会回调success,经验证会回调complete,然后就调试
发现有一个错误undefined is not a function 找到代码是这样的
var $io = $('<iframe id="' + id + '" name="' + id + '" src="' + opts.iframeSrc + '" onload="(jQuery(this).data(\'form-plugin-onload\'))()" />');
插件自己创建个iframe onload里面报错,该了一下改成onload="(function(){....})()"。
很明显这样虽然没有报错了,但是这不是没有调用success方法的原因,继续看看源码发现有个timeout参数,如果timeout有值的话就会反复执行一个方法,出发success的地方就在这里
if (opts.timeout)
setTimeout(function() {
timedOut = true;
cb();
}, opts.timeout);
function cb() {
if (cbInvoked)
return;
var ok = true;
try {
if (timedOut)
throw 'timeout';
var data, doc;
doc = io.contentWindow ? io.contentWindow.document
: io.contentDocument ? io.contentDocument
: io.document;
var isXml = opts.dataType == 'xml' || doc.XMLDocument
|| $.isXMLDoc(doc);
log('isXml=' + isXml);
if (!isXml
&& (doc.body == null || doc.body.innerHTML == '')) {
if (--domCheckCount) {
log('requeing onLoad callback, DOM not available');
setTimeout(cb, 250);
return;
}
log('Could not access iframe DOM after 100 tries.');
return;
}
log('response detected');
cbInvoked = true;
xhr.responseText = doc.body ? doc.body.innerHTML : null;
xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
xhr.getResponseHeader = function(header) {
var headers = {
'content-type' : opts.dataType
};
return headers[header];
};
if (opts.dataType == 'json' || opts.dataType == 'script') {
var ta = doc.getElementsByTagName('textarea')[0];
if (ta)
xhr.responseText = ta.value;
else {
var pre = doc.getElementsByTagName('pre')[0];
if (pre)
xhr.responseText = pre.innerHTML;
}
} else if (opts.dataType == 'xml' && !xhr.responseXML
&& xhr.responseText != null) {
xhr.responseXML = toXml(xhr.responseText);
}
data = $.httpData(xhr, opts.dataType);
} catch (e) {
log('error caught:', e);
ok = false;
xhr.error = e;
$.handleError(opts, xhr, 'error', e);
}
if (ok) {
opts.success(data, 'success');
if (g)
$.event.trigger("ajaxSuccess", [ xhr, opts ]);
}
if (g)
$.event.trigger("ajaxComplete", [ xhr, opts ]);
if (g && !--$.active)
$.event.trigger("ajaxStop");
if (opts.complete)
opts.complete(xhr, ok ? 'success' : 'error');
setTimeout(function() {
$io.removeData('form-plugin-onload');
$io.remove();
xhr.responseXML = null;
}, 100);
}
这么长的函数我没仔细看完的,然后设置了一下timeout参数
结果不行,报了个timeout异常,看看代码,发现在setTimeout的时候有一句timeOut=true,然后才执行cb()的,而cb刚开始try就有一个if(timeOut) throw "timeout",我不知到作者是什么意图,我动手改了
又碰到一个问题,$.httpData is not a function,try里面的最后一句
data = $.httpData(xhr, opts.dataType);
可能是想把结果转换成dataType指定的类型,不过我没有找到$.httpData的定义,也许插件还有其他附带的js,因为我用的都是返回json所以自己统一当作json处理,终于达到目的了。
其实本人js不是很精通,只是这样做达到自己目的了,但是在网络上似乎没找到谁遇到和我一样的问题,如果有发现真实原因还请告知啊。
ajaxSubmit提交文件表单不执行success的更多相关文章
- DWZ框架中ajax提交文件表单的处理(关闭当前dialog + 刷新父级navTab)
先重点关注两个js文件:dwz.ajax.js和dwz.core.js 流程: 1.回调iframeCallback <form xx enctype="multipart/form- ...
- ajaxSubmit 提交form 表单
$(document).on('click','#submit_title_btn',function(){ var title = $("#title").val(); if ( ...
- 使用ajax提交form表单,包括ajax文件上传 转http://www.cnblogs.com/zhuxiaojie/p/4783939.html
使用ajax提交form表单,包括ajax文件上传 前言 使用ajax请求数据,很多人都会,比如说: $.post(path,{data:data},function(data){ ... },&qu ...
- Ajax提交form表单内容和文件(jQuery.form.js)
jQuery官网是这样介绍form.js A simple way to AJAX-ify any form on your page; with file upload and progress s ...
- ajax 提交所有表单内容及上传图片(文件),以及单独上传某个图片(文件)
我以演示上传图片为例子: java代码如下(前端童鞋可以直接跳过看下面的html及js): package com.vatuu.web.action; import java.io.File; imp ...
- formidable处理提交的表单或文件的简单介绍
一般来说,客户端向服务端提交数据有GET和POST这两种方式,在之前的文章node.js当中的http模块与url模块的简单介绍当中我们可以知道通过req.url与url模块的配合处理可以快速得到客户 ...
- formidable处理提交的表单或图片文件的简单介绍
一般来说,客户端向服务端提交数据有GET和POST这两种方式,在之前的文章node.js当中的http模块与url模块的简单介绍当中我们可以知道通过req.url与url模块的配合处理可以快速得到客户 ...
- 使用ajax提交form表单,包括ajax文件上传【转载】
[使用ajax提交form表单,包括ajax文件上传] 前言 转载:作者:https://www.cnblogs.com/zhuxiaojie/p/4783939.html 使用ajax请求数据,很多 ...
- ajax提交form表单资料详细汇总
一.ajax提交form表单和不同的form表单的提交主要区别在于,ajax提交表单是异步提交的,而普通的是同步提交的表单.通过在后台与服务器进行少量数据交换,ajax 可以使网页实现异步更新.这意味 ...
随机推荐
- 【MFC相关】图片显示
CPaintDC dc(this); if (!m_hBitmap) return; image.Attach(m_hBitmap); CRect rect; GetClientRect(&r ...
- C语言选择法排序
#include <stdio.h> int main() { int i, j, p, n, q; ] = {, , , , }; //对无序数组进行排序 ; i<; i++) { ...
- Windows Phone 8初学者开发—第3部分:编写第一个Windows Phone 8应用程序
原文 Windows Phone 8初学者开发—第3部分:编写第一个Windows Phone 8应用程序 原文地址: http://channel9.msdn.com/Series/Windows- ...
- Error creating bean with name 'enableRedisKeyspaceNotificationsInitializer'
@Configuration public class HttpSessionConfig { @Bean public static ConfigureRedisAction configureRe ...
- Java chapter04-1
public class CPU { int speed; //获得speed的值 public void setSpeed(int m){ speed = m; } //返回speed的值 publ ...
- UVA 10057 A mid-summer night's dream. 仲夏夜之梦 求中位数
题意:求中位数,以及能成为中位数的数的个数,以及选择不同中位数中间的可能性. 也就是说当数组个数为奇数时,中位数就只有一个,中间那个以及中位数相等的数都能成为中位数,选择的中位数就只有一种可能:如果为 ...
- HDU 2570:迷瘴
迷瘴 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...
- ViewPager引导页效果实例源码
首先大家先找到本地的sdk,然后找到Google提供的API,具体查找方法如下:sdk——>docs——>index.html——>develop——>training——&g ...
- if语句求三个数中最大的
Console.WriteLine("请输入第一个数:"); int a = Convert.ToInt32( Console.ReadLine()); Console.Write ...
- c.Tom and paper
Tom and paper Description There is a piece of paper in front of Tom, its length and width are intege ...