Tengo un formulario que carga un archivo y apunta a un iframe en la página. Cuando el usuario hace clic en enviar, quiero que el contenido del archivo se "borre".
probé esto
$('#imageaddform').submit(function(){ $('#imagefile').val(''); });Pero borra el formulario antes del envío, por lo que nunca se carga nada.
¿Cómo borro después de enviar?
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 });La solución de Lonesomeday funcionó para mí, pero para Google Chrome descubrí que aún 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); });Podrías hacer algo como esto:
$('#imageaddform').submit(function(){ setTimeout(function() { $('#imagefile').val(''); },100); });