Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. $(function () {
  2.  
  3. var file_data = $('#upload-file-' + i).prop("files")[0]; // Getting the properties of file from file field
  4. var urlToPost = 'path/of/your/route';
  5. var form_data = new FormData(); // Creating object of FormData class
  6.  
  7. form_data.append("file_data", file_data); // Appending parameter named file with properties of file_field to form_data
  8. form_data.append("prestationId", prestationId); // Appending parameter named file with properties of file_field to form_data
  9. form_data.append("prestationQuantite", prestationQuantite); // Appending parameter named file with properties of file_field to form_data
  10. form_data.append("hasOption1", hasOption1); // Appending parameter named file with properties of file_field to form_data
  11. form_data.append("hasOption2", hasOption2); // Appending parameter named file with properties of file_field to form_data
  12. // form_data.append("user_id", 123) // Adding extra parameters to form_data
  13.  
  14. $.ajax({
  15. url: urlToPost, // Upload Script
  16. dataType: 'script',
  17. cache: false,
  18. async: false,
  19. contentType: false, // Important
  20. processData: false, // Important
  21. data: form_data, // Setting the data attribute of ajax with file_data
  22. type: 'post',
  23. success: function(data) {
  24. // Do something after Ajax completes
  25. }
  26. });
  27. // if your have a illega message you have to hade this
  28. // contentType: false, // Important
  29. // processData: false, // Important
  30. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement