jquery - How to send a form using javascript without being redirected? -


i use work submit(callback) jquery method, in callback serialize form , ajax post call.

but time, need upload file, , method desn't seems work, try directly submit form submit() jquery method, not able avoid redirection, calling e.preventdefault(); before:

$('form.input.upload').change(function(e) {   e.preventdefault();   $('form.example').submit(); }); 

you have preventdefault in onsubmit event of <form>, not in onchange event of <input>:

$("form.example").on("submit", function (e) {   // preventing browser's native form submit   e.preventdefault(); });  $("form.example input.upload").on("change", function (e) {   // auto-submit if input.upload changed   $("form.example").submit(); }); 

update: before edit wasn't correct. onsubmit event fired clicking on <input type="submit"> or pressing enter in focused <input>. but: event not triggered if call submit() function programmatically.

and well, thinking deeper, real problem - file uploading - bit harder answer. comment linked question has answer ;)


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -