如何使用jquery+;nodejs

如何使用jquery+;nodejs,jquery,node.js,file-upload,express,progress-bar,Jquery,Node.js,File Upload,Express,Progress Bar,我正在尝试使用jquery、ajax、express和nodejs上传一个文件。这里我想展示一下上传的进度。可能有插件或其他东西。不需要张贴答案。我想研究这背后的技术。所以,如果你知道如何处理这件事,请帮助我。我有一个ajax调用来上传文件 $.ajax({ url:'/controller/action', //remaining parameters }); 我找到了这个密码。我想这会对你有帮助。你也可以使用这个插件 您可以使用Multer上载您的文件: 目前Multer

我正在尝试使用jquery、ajax、express和nodejs上传一个文件。这里我想展示一下上传的进度。可能有插件或其他东西。不需要张贴答案。我想研究这背后的技术。所以,如果你知道如何处理这件事,请帮助我。我有一个ajax调用来上传文件

$.ajax({
    url:'/controller/action',
    //remaining parameters 
});

我找到了这个密码。我想这会对你有帮助。你也可以使用这个插件


您可以使用Multer上载您的文件:

目前Multer不提供进度跟踪:
this.uploadFile =  function(index) {
    //baseClass == this
    var file = baseClass.allFiles[index];

    //Creating instance of FormData
    var data = new FormData();
    //Adding file
    data.append('uploadFile', file.file);

    //Sending it with ajax
    $.ajax({
        url: '/',
        data: data,
        cache: false,
        contentType: false,
        processData: false,
        type: 'POST',
        success: function(response) {
            var message = file.element.find('td.message');
            if(response.status == 'ok') {
                message.html(response.text);
                file.element.find('button.uploadButton').remove();
            }
            else {
                message.html(response.errors);
            }
        },
        xhr: function() {
            var xhr = $.ajaxSettings.xhr();

            if ( xhr.upload ) {
                console.log('xhr upload');

                xhr.upload.onprogress = function(e) {
                    file.progressDone = e.position || e.loaded;
                    file.progressTotal = e.totalSize || e.total;
                    //updating downloading progress for the file
                    baseClass.updateFileProgress(index, file.progressDone, file.progressTotal, file.element);

                    //updating total progress
                    baseClass.totalProgressUpdated();
                };
            }

            return xhr;
        }
    });
};