0

I have input elements in my html page. When user presses the submit button, it being binded to the click even in jquery and the data is being validated and then send to server using AJAX. The problem is, I have a file field. So how to initiate the uploading of the file via the code using AJAX ?

Sample code:

$(function(){
  $('#btnSubmit').on('click', function(){
    // validate fields, make some processing on the data, etc.
    // then send to server using AJAX...

    $.ajax({
      //.... 
    });

    // after submitting the above data or along with it, I want the picture uploaded(without user having to press upload button or anything)
  });
});

How it can be done?

Vpp Man
  • 2,384
  • 8
  • 43
  • 74
  • My suggestion would be to google "ajax file upload" there are a few good plugins out there designed to do exactly this – Liath Aug 19 '14 at 09:43
  • Yes I have looked at some of the jQuery plugins. But the examples mentioned are like it will upload the file right after we select the image. What I want is, the uploading to be initiated via code. Because I had to do other processing on the user inputted data(some texts, dropdowns, etc) before sending to server! – Vpp Man Aug 19 '14 at 09:55
  • try this. http://stackoverflow.com/questions/19447435/ajax-upload-image – Ganesh Gaxy Aug 19 '14 at 09:58

0 Answers0