ajax formdata: Invocación ilegal
Intento hacer un script ajax para subir para Symfony 2. Chrome devuelve este error:
Uncaught TypeError: jquery de invocación ilegal.min.js: 4
Creo que se debe a que el objeto FormData
no está correctamente construido (pruebo el script con .serialized()
:
$(document).ready(function() {
$('#formImage').submit(function(event) {
event.preventDefault();
// appel Ajax
alert("ajax");
var input = document.getElementById("rasta_blogbundle_imagetype_file");
console.log(input);
var formdata = false;
if (window.FormData) {
formdata = new FormData();
console.log('formdata initialized ...');
}
else{
console.log('formdata not supported');
}
formdata.append('name',$('#rasta_blogbundle_imagetype_name').val());
console.log(formdata);
formdata.append('file',input);
formdata.append('_token',$('#rasta_blogbundle_imagetype__token').val());
console.log(formdata);
//alert(DATA);
if (formdata){
$.ajax({
url: $(this).attr('action'), // le nom du fichier indiqué dans le formulaire
type: $(this).attr('method'), // la méthode indiquée dans le formulaire (get ou post)
cache: false,
//data : $(this).serialize(),
data: formdata ,
success: function(data) { // je récupère la réponse du fichier PHP
$('#myModal').html(data);
console.log('ok');
}
//return false; //
});
}
});
});
24
2 answers
JQuery intenta transformar su objeto FormData en una cadena, agregue esto a su string.llamada ajax:
processData: false,
contentType: false
68
Author: djangonaut,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-03-03 01:26:53
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-03-03 01:26:53
Se produce en algún momento cuando jquery internamente no serializar los datos correctamente los datos para arreglarlo añadir esto.
cache : false,
dataType : 'json',
processData : false,
0
Author: user889030,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-05 13:09:10
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-05 13:09:10