Serialize file type jQuery

后端 未结 4 1601
长发绾君心
长发绾君心 2021-02-08 08:34

I\'m trying to serialize my form data including file image field using jquery.form.js jQuery API. The API is helping me to serailze data fields including image

4条回答
  •  一向
    一向 (楼主)
    2021-02-08 08:56

    let me help you. I made this just 1 day ago. I have form including image field. when you submit it its uploading image via jquery.form.js

    Note: I am uploading file with jqueryimageupload.php, if you want I can paste it. It is a simple php file upload. http://www.w3schools.com/php/php_file_upload.asp

    html part:

    jquery:

    function ImageUpload() {
        $("#return").show();
        $("#return").html('');
        $("#return").html('Uploading.... wait, uploading...');
        $("#imageform").ajaxForm({
            target: '#return',
            success: function() {
                $("#return").fadeOut(10000);
            }
       }).submit();     
    }
    

    at last form submit:

    $('#form').submit(function() {
        var img=$('#image').val();
        var forms=($(this).serialize());
        $.ajax({
            type:"POST",            
            url: "do.php?do=upload",
            data:forms+'&r='+encodeURIComponent(img),
            success: function(result){ //your code }     
        });
     });
    

提交回复
热议问题