使用 Ajax 时如何在 oncomplete 中调用函数

问题描述 投票:0回答:1

第一次在这里写。也是我第一次接触 ajax,我有点卡住了。

我有变量:

$upload = $application->buildLink('do=upload');
$do = $application->buildLink('do=read-excel');

每个人都用类调用另一个文件。第一个将给定文件上传到上传文件夹,另一个读取上传的文件(例如 xlm)。

然后我有这个脚本,在选择要上传的文件后开始

 uploader_1 = new qq.FileUploader({
                    element: document.getElementById('file-uploader'),
                    action: '$upload',
                    debug: true,
                    multiple: false,
                    allowedExtensions: ['csv','xlsx','xls'],
                    maxConnections: 1,
                    name: 'file-uploader',
                    dragDrop: true,
                    params: {
                        't': new Date().getTime();
                    },
                    template: '<div class="qq-uploader">'
                              + '<div class="qq-upload-drop-area">'
                              + '<span>Drag your file</span></div>'
                              + '<div class="qq-upload-button btn btn-default btn-sm">Select file</div>'
                              + '<ul class="qq-upload-list"></ul>'
                              + '</div>',

                    onSubmit: function(id, filename) {
                    },
                    onProgress: function(id, filename, loaded, total) {

                    },
                    onComplete: function(id, filename, responseJSON) {
                        $('.qq-upload-success').remove();
                        $('.qq-upload-fail').remove();
                        if (responseJSON['success'])
                        {
                            $('#file-uploader').html('Uploaded: ' + filename );
                        }
                        else
                        {
                            showError();
                        }
                    }

在“action:”里面我放了上传所以上传类被调用。然后 $upload 被调用。我想用 $do 做同样的事情,但我想在上传后做,可能在 onComplete 里面,但我不知道如何在里面调用它。

谢谢!

javascript php html ajax ajaxform
1个回答
0
投票
uploader_1 = new qq.FileUploader({
// ... your existing options ...
onComplete: function(id, filename, responseJSON) {
    $('.qq-upload-success').remove();
    $('.qq-upload-fail').remove();
    if (responseJSON['success']) {
        $('#file-uploader').html('Uploaded: ' + filename );
        // Make an AJAX request to $do
        $.ajax({
            url: '$do',
            type: 'POST',
            dataType: 'json',
            data: {
                // Any parameters you need to pass to $do
            },
            success: function(response) {
                // Handle the response from $do
            },
            error: function(xhr, status, error) {
                // Handle errors
            }
        });
    } else {
        showError();
    }
}});
© www.soinside.com 2019 - 2024. All rights reserved.