延迟ajax上传,直到用户点击按钮?

时间:2011-02-24 21:57:03

标签: javascript jquery html ajax jquery-plugins

我正在尝试使用this plugin,但我看不到轻松启用自动上传的方法。

我已经玩了一会儿,但我仍然没有一个好的解决方案。有没有人看到我如何阻止自动上传并在其他一些动作上触发上传?

2 个答案:

答案 0 :(得分:0)

这是我使用的插件,不需要flash(获取插件):http://plugins.jquery.com/project/ajaxFileUpload

您可以通过以下方式调用它:

$.ajaxFileUpload({
        url:file_uppload_url_here,
        secureuri:false,
        fileElementId: file_element_id_here,
        dataType: 'json',
        success: function (data, status)
        {

        },
        send: function(data)
        {
        },
        error: function (data, status, e)
        {
            console.debug(data);
        }
    }
)

答案 1 :(得分:-1)

由于这是特定于插件的,因此最好的办法是查看其github repo上的源代码并覆盖拖放事件。

看起来也可以通过选项覆盖onSubmit功能,但我假设你已经尝试过了。

var uploader = new qq.FileUploader({
    // pass the dom node (ex. $(selector)[0] for jQuery users)
    element: document.getElementById('file-uploader'),
    // path to server-side upload script
     action: '/server/upload',

    // events         
    // you can return false to abort submit
    onSubmit: function( id, filename ){
       // do something
    }
});