The problem is, there is ajax upload file upload, everything works, but I want to transfer along with the file the value of the select in postData: I tried this way and that, it doesn’t work out how to do it properly, advise, here is the select and the upload script transfers only that select that was selected when the page loads

$('document').ready(function ($, data) { $('.upload').upload({ action: '/admin/upload', label: 'ΠŸΠ΅Ρ€Π΅Ρ‚Π°Ρ‰ΠΈΡ‚Π΅ Ρ„Π°ΠΉΠ» ΠΈΠ»ΠΈ ΠΊΠ»ΠΈΠΊΠ½ΠΈΡ‚Π΅ для Π²Ρ‹Π±ΠΎΡ€Π°', postKey: 'newfile', maxQueue: 1, postData: ({data: data = $('#my_select').val()}), maxSize: 300485760 }).on("start.upload", Start) .on("filestart.upload", fileStart) .on("fileprogress.upload", fileProgress) .on("filecomplete.upload", filePComplelele) .on("fileerror.upload", fileError) .on("complete.upload", Complete); }); 
 <select id="my_select"> <option value="1">Бписок 1<option> <option value="2">Бписок 2<option> <option value="3">Бписок 3<option> <option value="4">Бписок 4<option> </select> 

  • $('#my_select option:selected').val() ? - Alexey Shimansky
  • the same thing, it transmits the current which was chosen when loading, but not the one that I choose (( - Dima
  • well and send after the choice, but not loading of the document. - Jean-Claude
  • try to render data = $ ('# my_select'). val () before upload is initialized, and then transfer the variable to postData - Maks Devda
  • I tried it the same way, I need it through change () only as - Dima

1 answer 1

Judging by your script, the upload request is just sent when the page loads. And at this moment it is quite logical that according to your selector, just the select that is set at boot time is returned.

The upload call must be linked to something like a button click, and inside the handler to calculate:

 $('#my_select').val();