javascript - Mixed inputs (text and file) to send through $.ajax using data -
i tried send data 2 inputs php code, 1 of them text , other type file. second field multiple selection of files. well, here code of html section:
<input type="text" id="padron-documento" class="form-control input-lg" name="padron-documento" placeholder="padrĂ³n" /><br /> <div class="alert alert-info"> <input type="file" id="archivos" name="archivos[]" multiple onchange="seleccionado()" /> </div> <div id="cargados"> <!-- here display loaded files. --> </div>
ok, code of javascript section:
function seleccionado(){ var archivos = document.getelementbyid("archivos");//we value of input id archivos var archivo = archivos.files; //here value of input (archivos) array //teh formdata object allow create form passing key/value send it, kind of object have multipart/form-data upload files var datos = new formdata(); padron = $("#padron-documento").val(); //we don't know how files user upload, iterate variable //and pass key/value method append object formdata, use index "i" // avoid repeated values, if not use it, have value of last iteration for(i=0; i<archivo.length; i++){ datos.append('archivo'+i,archivo[i]); } $.ajax({ url:'subir.php', //url type:'post', //method contenttype:false, //it must false data: {padron,datos}, //we pass object create archivos , text id padron processdata:false, //it must false avoid jquery processing cache:false //avoid save cache }).done(function(msg) {$("#cargados").append(msg); //it show files loaded div "cargados"});} /*****************************/
i have php file, process uploaded file/s, it's works fine.ok, trouble it's going around sending "data" attribute $.ajax
object. how can send text chain such id number , file, both of them trough data attribute of $.ajax
object, example, know that: data: id:idnumber,file:filearray
, cannot make work way. file array of files , input text field that, text. help?
Comments
Post a Comment