Skip to content Skip to sidebar Skip to footer

How To Upload By Ajax Post Serialize

I have form upload:

Solution 1:

You don't need to serialize the form. Instead you should send an instance of the FormData class.

        $("form").submit(function(event) {
            event.preventDefault();

            var data = newFormData($(this)[0]);

            $.ajax({
                // Note: to access both $_POST and $_FILES you should set these to false
                processData : false,
                contentType : false,

                url : "/php-script.php",
                data : data,
                success : function(response){
                    console.log(response);
                }
            });
        });

That's a very common technique to send files via AJAX using jquery.

Post a Comment for "How To Upload By Ajax Post Serialize"