Ver Mensaje Individual
  #3 (permalink)  
Antiguo 18/04/2016, 03:57
Avatar de cluster28
cluster28
 
Fecha de Ingreso: enero-2008
Ubicación: Donostia - San Sebastián
Mensajes: 756
Antigüedad: 16 años, 4 meses
Puntos: 32
Respuesta: Subir Imagen(archivo) con Ajax Jquery y usarlo en Symfony2

Llevo más de dos horas con esto y en el request no aparece el formulario.

Código TWIG:
Ver original
  1. <div id="add-file">
  2.     <form id="form-file" action="{{ path('panel_archivos_add') }}" enctype="multipart/form-data" method="post">
  3.         <input id="fileupload" type="file" name="fichero"/>
  4.         <input type="hidden" name="subcarpeta" value=""/>
  5.         <input type="hidden" name="id_usuario" value=""/>
  6.         <input type="submit"></input>
  7.     </form>
  8. </div>
  9.    
  10. <script>
  11.    
  12.       $('#form-file').submit(function(event){
  13.            
  14.             event.preventDefault();
  15.  
  16.             $.ajax({
  17.  
  18.                     error:      function(jqXHR, textStatus, errorThrown){},
  19.                     data:       {
  20.                                     datos: new FormData($(this)[0])
  21.                                 },
  22.                     success:    function(data, textStatus, jqXHR)
  23.                                 {
  24.                                     console.log(data);
  25.                                 },
  26.                     url:        "{{ path('panel_archivos_add') }}",
  27.                     method:     "POST",
  28.                     processData: false,
  29.                     contentType: false,
  30.                     cache: false
  31.                 }
  32.             );
  33.         });
  34.  
  35. </script>

Si pongo esto, tampoco...

Código TWIG:
Ver original
  1. contentType: "multipart/form-data"