Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I do a jquery post for a file upload form?
    primarykey
    data
    text
    <p>I have a form that looks something like this:</p> <pre><code>&lt;form id="uploadForm" name="uploadForm" method="post" enctype="multipart/form-data"&gt; &lt;input type="file" id="uploadFile" name="uploadFile" /&gt;&lt;br /&gt; &lt;input type="submit" id="process" name="process" value="Process File" /&gt; &lt;/form&gt; </code></pre> <p>I want to allow the user to upload a file, and then process it. When the user hits "process" I want to call this page using a jquery post (this form is being shown in a cfwindow, and I don't want to leave the cfwindow), do some processing and output a message. This is the code I would usually use:</p> <pre><code>$('#process').click(function(){ $.post('&lt;cfoutput&gt;#cgi.script_name#&lt;/cfoutput&gt;', $('#uploadForm').serialize(), function(data){ ... some processing ... }); }); </code></pre> <p>However, nothing is being passed. Further investigation led me to the jquery documentation for the <a href="http://api.jquery.com/serialize/" rel="nofollow">serialize</a> function, which states:</p> <blockquote> <p>Data from file select elements is not serialized.</p> </blockquote> <p>How can I pass the file select element?</p> <p>(If this makes a difference - when I post to the page I'm using this code to read the file that is uploaded in the file select element:</p> <pre><code>&lt;cfspreadsheet action="read" src="#form.uploadFile#" sheet="1" query="spreadsheetData" headerRow="1" excludeHeaderRow="true"&gt; </code></pre> <p>Originally I was just using the regular form post and it was working perfectly. I'd like to switch over to ajax so that I can keep the cfwindow open instead of reloading.)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload