/ Ajax File Uploader

AjaxFileUpload - Jquery Ajax文件上传插件

AjaxFileUpload是用一个使用Ajax上传指定表单元素文件的jQuery插件,实现原理为创建一个iframe,将制定表单提交到iframe,然后再做进一步处理。

使用方法

1.引入jquery.js和ajaxfileupload.js 2.创建文件上传函数,如:
function ajaxFileUpload() {
    //starting setting some animation when the ajax starts and completes
    $("#loading")
            .ajaxStart(function () {
                $(this).show();
            })
            .ajaxComplete(function () {
                $(this).hide();
            });
/*
 prepareing ajax file upload
 url: the url of script file handling the uploaded files
 fileElementId: the file type of input element id and it will be the index of  $_FILES Array()
 dataType: it support json, xml
 secureuri:use secure protocol
 success: call back function when the ajax complete
 error: callback function when the ajax failed

 */
$.ajaxFileUpload
        (
                {
                    url:'doajaxfileupload.php',
                    secureuri:false,
                    fileElementId:'fileToUpload',
                    dataType:'json',
                    success:function (data, status) {
                        if (typeof(data.error) != 'undefined') {
                            if (data.error != '') {
                                alert(data.error);
                            } else {
                                alert(data.msg);
                            }
                        }
                    },
                    error:function (data, status, e) {
                        alert(e);
                    }
                }
        )

return false;

}

插件下载

Click Here to download

Demo

Click here to test it