0

I'm Using front-end angularjs, there is a file upload option. When I upload a file it will pass to back-end Java Web services and It will insert into database. So this is the flow I have to do.

My problem is, How can I pass the file using JSON AJAX to the web services, Please let me know further any questions required.

Thanks in Advance.

VinothPHP
  • 821
  • 2
  • 10
  • 22

2 Answers2

0

AJAX doesnt support file uploading. you can use formdata for fileupload but this work for only html5 supported browsers.And if you want it to work even for older browsers you can use iframe with form for fileupload.

var form = $('form')[0]; 
var formData = new FormData(form);

$.ajax({
   url: 'submitNewSection.html',
   data: data,
   type: 'POST',
   success: function ( data ) {
     alert( data );
   }
});
Alok Pathak
  • 875
  • 1
  • 8
  • 20
0

Try

    $.ajax({
        type: "POST",
        url: "url",
        data: JSON.stringify(formdata),
        contentType: 'multipart/form-data',
        success: function (result) {}
    });
Rahaman
  • 323
  • 1
  • 9