修复上传组件问题
This commit is contained in:
@@ -4,7 +4,6 @@ jQuery.extend({
|
|||||||
if (s.error) {
|
if (s.error) {
|
||||||
s.error.call(s.context || s, xhr, status, e);
|
s.error.call(s.context || s, xhr, status, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fire the global callback
|
// Fire the global callback
|
||||||
if (s.global) {
|
if (s.global) {
|
||||||
(s.context ? jQuery(s.context) : jQuery.event).trigger("ajaxError", [xhr, s, e]);
|
(s.context ? jQuery(s.context) : jQuery.event).trigger("ajaxError", [xhr, s, e]);
|
||||||
@@ -13,17 +12,14 @@ jQuery.extend({
|
|||||||
createUploadIframe: function (id, uri) {
|
createUploadIframe: function (id, uri) {
|
||||||
//create frame
|
//create frame
|
||||||
var frameId = 'jUploadFrame' + id;
|
var frameId = 'jUploadFrame' + id;
|
||||||
|
|
||||||
if (window.ActiveXObject) {
|
if (window.ActiveXObject) {
|
||||||
var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />');
|
var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />');
|
||||||
if (typeof uri == 'boolean') {
|
if (typeof uri == 'boolean') {
|
||||||
io.src = 'javascript:false';
|
io.src = 'javascript:false';
|
||||||
}
|
} else if (typeof uri == 'string') {
|
||||||
else if (typeof uri == 'string') {
|
|
||||||
io.src = uri;
|
io.src = uri;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
io = document.createElement('iframe');
|
io = document.createElement('iframe');
|
||||||
io.id = frameId;
|
io.id = frameId;
|
||||||
io.name = frameId;
|
io.name = frameId;
|
||||||
@@ -31,10 +27,8 @@ jQuery.extend({
|
|||||||
io.style.position = 'absolute';
|
io.style.position = 'absolute';
|
||||||
io.style.top = '-1000px';
|
io.style.top = '-1000px';
|
||||||
io.style.left = '-1000px';
|
io.style.left = '-1000px';
|
||||||
|
|
||||||
document.body.appendChild(io);
|
document.body.appendChild(io);
|
||||||
|
return io;
|
||||||
return io
|
|
||||||
},
|
},
|
||||||
createUploadForm: function (id, fileElementId) {
|
createUploadForm: function (id, fileElementId) {
|
||||||
//create form
|
//create form
|
||||||
@@ -58,7 +52,6 @@ jQuery.extend({
|
|||||||
$(form).appendTo('body');
|
$(form).appendTo('body');
|
||||||
return form;
|
return form;
|
||||||
},
|
},
|
||||||
|
|
||||||
ajaxFileUpload: function (s) {
|
ajaxFileUpload: function (s) {
|
||||||
// TODO introduce global settings, allowing the client to modify them for all requests, not only timeout
|
// TODO introduce global settings, allowing the client to modify them for all requests, not only timeout
|
||||||
s = jQuery.extend({}, jQuery.ajaxSettings, s);
|
s = jQuery.extend({}, jQuery.ajaxSettings, s);
|
||||||
@@ -73,7 +66,7 @@ jQuery.extend({
|
|||||||
}
|
}
|
||||||
var requestDone = false;
|
var requestDone = false;
|
||||||
// Create the request object
|
// Create the request object
|
||||||
var xml = {}
|
var xml = {};
|
||||||
if (s.global)
|
if (s.global)
|
||||||
jQuery.event.trigger("ajaxSend", [xml, s]);
|
jQuery.event.trigger("ajaxSend", [xml, s]);
|
||||||
// Wait for a response to come back
|
// Wait for a response to come back
|
||||||
@@ -103,7 +96,6 @@ jQuery.extend({
|
|||||||
// If a local callback was specified, fire it and pass it the data
|
// If a local callback was specified, fire it and pass it the data
|
||||||
if (s.success)
|
if (s.success)
|
||||||
s.success(data, status);
|
s.success(data, status);
|
||||||
|
|
||||||
// Fire the global callback
|
// Fire the global callback
|
||||||
if (s.global)
|
if (s.global)
|
||||||
jQuery.event.trigger("ajaxSuccess", [xml, s]);
|
jQuery.event.trigger("ajaxSuccess", [xml, s]);
|
||||||
@@ -117,30 +109,22 @@ jQuery.extend({
|
|||||||
// The request was completed
|
// The request was completed
|
||||||
if (s.global)
|
if (s.global)
|
||||||
jQuery.event.trigger("ajaxComplete", [xml, s]);
|
jQuery.event.trigger("ajaxComplete", [xml, s]);
|
||||||
|
|
||||||
// Handle the global AJAX counter
|
// Handle the global AJAX counter
|
||||||
if (s.global && ! --jQuery.active)
|
if (s.global && ! --jQuery.active)
|
||||||
jQuery.event.trigger("ajaxStop");
|
jQuery.event.trigger("ajaxStop");
|
||||||
|
|
||||||
// Process result
|
// Process result
|
||||||
if (s.complete)
|
if (s.complete)
|
||||||
s.complete(xml, status);
|
s.complete(xml, status);
|
||||||
|
jQuery(io).unbind();
|
||||||
jQuery(io).unbind()
|
|
||||||
|
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
try {
|
try {
|
||||||
$(io).remove();
|
$(io).remove();
|
||||||
$(form).remove();
|
$(form).remove();
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
jQuery.handleError(s, xml, null, e);
|
jQuery.handleError(s, xml, null, e);
|
||||||
}
|
}
|
||||||
|
}, 100);
|
||||||
}, 100)
|
xml = null;
|
||||||
|
|
||||||
xml = null
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Timeout checker
|
// Timeout checker
|
||||||
@@ -158,12 +142,23 @@ jQuery.extend({
|
|||||||
$(form).attr('target', frameId);
|
$(form).attr('target', frameId);
|
||||||
if (form.encoding) {
|
if (form.encoding) {
|
||||||
form.encoding = 'multipart/form-data';
|
form.encoding = 'multipart/form-data';
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
form.enctype = 'multipart/form-data';
|
form.enctype = 'multipart/form-data';
|
||||||
}
|
}
|
||||||
$(form).submit();
|
let submitType = s.submitType;
|
||||||
|
let $form = $(form);
|
||||||
|
if (!submitType || submitType == 'form') {
|
||||||
|
$form.submit();
|
||||||
|
} else if (submitType == 'ajax') {
|
||||||
|
$form.ajaxSubmit({
|
||||||
|
success: function (data, status) {
|
||||||
|
s.success(data, status);
|
||||||
|
},
|
||||||
|
error: function (err) {
|
||||||
|
jQuery.handleError(s, xml, null, err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
jQuery.handleError(s, xml, null, e);
|
jQuery.handleError(s, xml, null, e);
|
||||||
}
|
}
|
||||||
@@ -174,9 +169,7 @@ jQuery.extend({
|
|||||||
document.getElementById(frameId).addEventListener('load', uploadCallback, false);
|
document.getElementById(frameId).addEventListener('load', uploadCallback, false);
|
||||||
}
|
}
|
||||||
return { abort: function () { } };
|
return { abort: function () { } };
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
uploadHttpData: function (r, type) {
|
uploadHttpData: function (r, type) {
|
||||||
var data = !type;
|
var data = !type;
|
||||||
data = type == "xml" || data ? r.responseXML : r.responseText;
|
data = type == "xml" || data ? r.responseXML : r.responseText;
|
||||||
|
Reference in New Issue
Block a user