jquery ajax load image code example

Example: jquery ajax upload image

$(function() {
            $("#imagepicker").change(function(e) {
                e.preventDefault();
                var file_data = $(this).prop('files')[0];
                var form_data = new FormData();

                form_data.append('file', file_data);
                form_data.append('action', 'ajax_image_upload');

                $.ajax({
                    url: 'upload.php',
                    type: 'post',
                    contentType: false,
                    processData: false,
                    data: form_data,
                    success: function(response) {
                        console.log(response);

                    },
                    error: function(response) {
                        console.error(response.responseText);
                    }

                });
            });
        });