¿Hay una opción de jQuery" después de enviar"?
Tengo un formulario que carga un archivo y se dirige a un iframe en la página. Cuando el usuario hace clic en enviar, quiero que el contenido del archivo se "borre".
He intentado esto
$('#imageaddform').submit(function(){
$('#imagefile').val('');
});
Pero borra el formulario antes del envío, por lo que nunca se carga nada.
¿Cómo puedo limpiar después de enviar?
4 answers
Si no tiene otros controladores vinculados, podría hacer algo como esto:
$('#imageaddform').submit(function(e) {
e.preventDefault(); // don't submit multiple times
this.submit(); // use the native submit method of the form element
$('#imagefile').val(''); // blank the input
});
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
2011-03-02 15:20:04
La solución de Lonesomeday funcionó para mí, pero para Google Chrome encontré que todavía enviaría datos de formulario vacíos a menos que agregara un tiempo de espera como este:
$('#imageaddform').submit(function(e) {
e.preventDefault(); // don't submit multiple times
this.submit(); // use the native submit method of the form element
setTimeout(function(){ // Delay for Chrome
$('#imagefile').val(''); // blank the input
}, 100);
});
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
2011-11-05 20:02:17
Podrías hacer algo como esto:
$('#imageaddform').submit(function(){
setTimeout(function() {
$('#imagefile').val('');
},100);
});
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
2011-03-02 15:16:13
¿Cómo está enviando el formulario? si esto es un mensaje de formulario normal, entonces la página no existirá en ese caso me pregunto si está buscando borrar el formulario antes de que la página se actualice para que cuando el usuario regrese no vea los valores poblados.
Si el formulario es enviado por ajax, entonces puede
function(){
$('form1')[0].submit();
clearForm();
}
¿Me perdí la pregunta?
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
2011-03-02 15:23:32