使用jQuery + Ajax + PHP 实现无刷新上传

<form id = "frm" >
    <div id = "box2" >
        <input type = "file" name = "file1" id = "file1" />
        <input type = "button" value = "上传" id = "upload" />
    </div>
</form>
$ ( "#upload" ). click ( function (){
    var formData = new FormData ( $ ( "#frm" )[ 0 ]);
    $ . ajax ({
        url : "https://blog.454142.com/ajaximg.php" ,
        type : 'POST' ,
        data : formData ,
        async : false ,
        cache : false ,
        contentType : false ,
        processData : false ,
        success : function ( res ) {
            alert ( res . str )
        },
        error : function ( res ) {
            alert ( res . str );
        }
    });
})

猜你喜欢

转载自blog.csdn.net/huyhuylop/article/details/80775957