wordpress ajax file upload

Solutions on MaxInterview for wordpress ajax file upload by the best coders in the world

showing results for - "wordpress ajax file upload"
Lucia
11 Jun 2017
1jQuery(document).on('click', '#submit', function(e){
2    e.preventDefault();
3
4    var fd = new FormData();
5    var file = jQuery(document).find('input[type="file"]');
6    var caption = jQuery(this).find('input[name=img_caption]');
7    var individual_file = file[0].files[0];
8    fd.append("file", individual_file);
9    var individual_capt = caption.val();
10    fd.append("caption", individual_capt);  
11    fd.append('action', 'fiu_upload_file');  
12
13    jQuery.ajax({
14        type: 'POST',
15        url: fiuajax.ajaxurl,
16        data: fd,
17        contentType: false,
18        processData: false,
19        success: function(response){
20
21            console.log(response);
22        }
23    });
24});
25