Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 KB | None | 0 0
  1. function dataForm_Archivos(formulario){
  2. var nuevoFormulario = new FormData();
  3. $(formulario).find(':input').each(function() {
  4. var elemento= this;
  5. //Si recibe tipo archivo 'file'
  6. if(elemento.type === 'file'){
  7. if(elemento.value !== ''){
  8. var file_data = $('input[type="file"]')[0].files;
  9. for (var i = 0; i < file_data.length; i++) {
  10. nuevoFormulario.append(elemento.name, file_data[i]);
  11. }
  12. }
  13. }
  14. }
  15. }
  16.  
  17. function registrarDocumentacion(formulario){
  18.  
  19. var datosForm = dataForm_Archivos(formulario);
  20. var request = $.ajax({
  21. contentType: false,
  22. processData: false,
  23. data: datosForm,
  24. type: 'POST',
  25. url: 'url',
  26. beforeSend:function(){
  27.  
  28. }
  29.  
  30. });
  31.  
  32. request.done(function(datos) {
  33.  
  34. });
  35. }
  36.  
  37. <form role="form" action='#?' id="registroDocumentacion" method="post">
  38. <div class="row">
  39. <div class="col-md-12">
  40. <div class="form-group">
  41. <label class="control-label">Adjuntar Archivo</label>
  42. <input type="file" id="arcAdjunto" name="arcAdjunto" class="filestyle" placeholder="Asunto" onchange="validarArchivo('#arcAdjunto');">
  43. <h5><small>Recuerde, los tipos de archivos permitidos son: png, gif, jpg, jpeg, docx, xls, xlsx, docs, pdf</small></h5>
  44. </div>
  45. </div>
  46. </div>
  47. <div class="row">
  48. <div class="col-md-12 text-left m-t-20">
  49. <button type="button" class="btn btn-primary waves-effect waves-light" id="enviarDoc" > Enviar <i class="fa fa-send" aria-hidden="true"></i> </button>
  50. </div>
  51. </div>
  52. </form>
  53.  
  54.  
  55. <script type="text/javascript">
  56. $('#enviarDoc').click(function(event) {
  57. registrarDocumentacion('#registroDocumentacion')
  58. });
  59. </script>
  60.  
  61. function dataForm_Archivos(formulario){
  62. var nuevoFormulario = new FormData();
  63. $(formulario).find(':input').each(function() {
  64. var elemento= this;
  65. //Si recibe tipo archivo 'file'
  66. if(elemento.type === 'file'){
  67. if(elemento.value !== ''){
  68. for(var i=0; i< $('#'+elemento.id).prop("files").length; i++){
  69. nuevoFormulario.append(elemento.name, $('#'+elemento.id).prop("files")[i]);
  70. }
  71. }
  72. }
  73. }
  74. return nuevoFormulario;
  75. }
  76.  
  77. var formData = new FormData();
  78.  
  79. formData.append("archivoDelUsuario", fileInputElement.files[0]); //Aquí capturas el fileInput seleccionado por el usuario
  80. var archivoBlob = new Blob([content], { type: "text/xml"}); //creamos un archivo tipo blob
  81. formData.append("elArchivo", archivoBlob); //listo agregamos el archivo
  82.  
  83. function dataForm_Archivos(formulario){
  84. var nuevoFormulario = new FormData();
  85. $(formulario).find(':input').each(function() {
  86. var elemento= this;
  87. //Si recibe tipo archivo 'file'
  88. if(elemento.type === 'file'){
  89. if(elemento.value !== ''){
  90. var file_data = $('input[type="file"]')[0].files;
  91. for (var i = 0; i < file_data.length; i++) {
  92. nuevoFormulario.append(elemento.name, file_data[i]);
  93. }
  94. }
  95. }
  96. }
  97.  
  98. return nuevoFormulario;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement