javascript - How do I simulate the behavior of a standard file field submit with an ajax post? -
due diligence
just clear have searched answer question , found these great questions unfortunately not me.
submit form including file upload via jquery ajax
jquery ajax submit form
jquery using ajax send data , save in php
jquery ajax submit form
setup
i have system pulling form values , posting them via ajax. simple snippet may like:
// values var url = '/ajax/my/controller' var values = mystuff.getformvalues($form); // post $.post(url, values, function($response) { if ($response['status']) { // success } else { // validation error. } }, 'json');
my getformvalues
functions runs custom processing make sure send information need keen on keeping it. similar jquery 'serialize' function simpler , custom processing.
the problem
my form values function $('selector').val()
form values. not upload file fields. returns fake path c:\fakepat\filename.png
. of course not work. need submit file part of ajax post operation.
the question
without switching jquery serialize (since doesn't support files anyway) , without using other libraries such jquery form, how obtain file file field , post using ajax?
simplified, how simulate behavior of standard file field submit ajax post?
Comments
Post a Comment