Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ jquery async upload plugin
easy to use

// 上传方法
```javascript
$.upload({
// 上传地址
url: '/admin/upload',
Expand All @@ -16,7 +17,8 @@ easy to use
return true;
},
// 上传之后回调
onComplate: function(data) {
onComplete: function(data) {
alert(data);
}
});
});
```
12 changes: 6 additions & 6 deletions jquery.upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
params: {},
onSend: noop,
onSubmit: noop,
onComplate: noop
onComplete: noop
};

$.upload = function(options) {
var opts = $.extend(jQuery.uploadDefault, options);
if (opts.url == '') {
if (!opts.url) {
return;
}

Expand All @@ -36,7 +36,7 @@

// form中增加数据域
var formHtml = '<input type="file" name="' + opts.fileName + '" onchange="onChooseFile(this)">';
for (key in opts.params) {
for (var key in opts.params) {
formHtml += '<input type="hidden" name="' + key + '" value="' + opts.params[key] + '">';
}
form.append(formHtml);
Expand All @@ -47,13 +47,13 @@
form.submit(opts.onSubmit);

// iframe 在提交完成之后
iframe.load(function() {
iframe.on('load', function() {
var contents = $(this).contents().get(0);
var data = $(contents).find('body').text();
if ('json' == opts.dataType) {
data = window.eval('(' + data + ')');
data = JSON.parse(data);
}
opts.onComplate(data);
opts.onComplete(data);
setTimeout(function() {
iframe.remove();
form.remove();
Expand Down