使用这个(jquery for fileupload)脚本我收到一些错误,但它在本地的 wamp 中工作。对于生产,我需要停止此警报错误”
“SyntaxError:属性列表
progressall之后缺少}:函数(e,数据){”
或在 Chrome 中:
“第 211 行未捕获的语法错误意外标识符”
与 Firefox 中的行相同。
有人有想法吗?
$(function () {
$('#fileupload').fileupload({
dataType: 'json',
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
}
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .bar').css(
'width',
progress + '%'
);
}
add: function (e, data) {
data.context = $('<p/>').text('Uploading...').appendTo(document.body);
data.submit();
}
done: function (e, data) {
data.context.text('Upload finished.');
}
add: function (e, data) {
data.context = $('<button/>').text('Upload')
.appendTo(document.body)
.click(function () {
$(this).replaceWith($('<p/>').text('Uploading...'));
data.submit();
});
}
done: function (e, data) {
data.context.text('Upload finished.');
}
});
});
我做了一些修改:Mozilla 没有错误但无法正常工作
在 chrome 错误中(Uncaught TypeError: Cannot call method 'push' of undefined)并且不工作
$(function () {
//declare a "updloadOptions" variable object that will be passed to the plugin constructor method as a parameter. (You can give any name to this object.)
var updloadOptions = {};
//set the datatype property to 'json'.
updloadOptions.dataType = 'json';
//declare the "done" callback method on "updloadOptions" object.
updloadOptions.done = function (e, data) {
$.each(data.result.files, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
};
//declare the "progressall" callback method on "updloadOptions" object.
updloadOptions.progressall = function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .bar').css(
'width',
progress + '%');
};
//declare the "add" callback method on "updloadOptions" object.
updloadOptions.add = function (e, data) {
data.context = $('<button/>').text('Upload')
.appendTo(document.body)
.click(function () { $(this).replaceWith($('<p/>').text('Uploading...'));
data.context = $('<p/>').text('Uploading...').appendTo(document.body);
data.submit();
});
};
//initialize the component
$('#fileupload').fileupload(updloadOptions);
});
语法错误的正确脚本
SyntaxError: 在属性列表
filesContainer: $('.filescontainer')之后缺少 }
而且我永远不需要filesContainer
,因为我用上传系统检索了第二个 jquery 选项卡
$(function () {
$('#fileupload').fileupload({
dataType: 'json',
done: function (e, data) {
$.each(data.result.files, function (index, file) {
$('<p/>').text(file.name).appendTo(document.body);
});
},
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#progress .bar').css(
'width',
progress + '%'
);
},
add: function (e, data) {
data.context = $('<p/>').text('Uploading...').appendTo(document.body);
data.submit();
},
done: function (e, data) {
data.context.text('Upload finished.')
},
add: function (e, data) {
data.context = $('<button/>').text('Upload')
.appendTo(document.body)
.click(function () {
$(this).replaceWith($('<p/>').text('Uploading...'));
data.submit();
});
}, done: function (e, data) {
data.context.text('Upload finished.')
}
filesContainer: $('.filescontainer')
});
});