Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(function () {
- var file_data = $('#upload-file-' + i).prop("files")[0]; // Getting the properties of file from file field
- var urlToPost = 'path/of/your/route';
- var form_data = new FormData(); // Creating object of FormData class
- form_data.append("file_data", file_data); // Appending parameter named file with properties of file_field to form_data
- form_data.append("prestationId", prestationId); // Appending parameter named file with properties of file_field to form_data
- form_data.append("prestationQuantite", prestationQuantite); // Appending parameter named file with properties of file_field to form_data
- form_data.append("hasOption1", hasOption1); // Appending parameter named file with properties of file_field to form_data
- form_data.append("hasOption2", hasOption2); // Appending parameter named file with properties of file_field to form_data
- // form_data.append("user_id", 123) // Adding extra parameters to form_data
- $.ajax({
- url: urlToPost, // Upload Script
- dataType: 'script',
- cache: false,
- async: false,
- contentType: false, // Important
- processData: false, // Important
- data: form_data, // Setting the data attribute of ajax with file_data
- type: 'post',
- success: function(data) {
- // Do something after Ajax completes
- }
- });
- // if your have a illega message you have to hade this
- // contentType: false, // Important
- // processData: false, // Important
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement