Forum: Ruby on Rails Ajax file upload with remote_form_tag

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Amol N. (Guest)
on 2009-03-18 09:41
when I tried below, it worked

<form
 target="upload_iframe"
 action="/profile/validate_charts_file"
 id="upload_charts"
 method="post"
 enctype="multipart/form-data">
  <input type="file" name="charts_file" id="filename" />
  <input type="button" name="submit" class="button_light" value="Upload"
/>
</form>
<iframe id="upload_iframe" name="upload_frame" style="display:
none"></iframe>

I could receive the file at server end through params[:charts_file].

Now i wanted to have it ajax so I just added the 'onSubmit' like below,
and it didnt work ...

<form
 target="upload_iframe"
 action="/profile/validate_charts_file"
 id="upload_charts"
 onsubmit="new Ajax.Request('/profile/validate_charts_file',
    {asynchronous:true, evalScripts:true,
    parameters:Form.serialize(this)});return false;"
 method="post"
 enctype="multipart/form-data">
  <input type="file" name="charts_file" id="filename" />
  <input type="button" name="submit" class="button_light" value="Upload"
/>
</form>
<iframe id="upload_iframe" name="upload_frame" style="display:
none"></iframe>
Amol N. (Guest)
on 2009-03-18 09:49
one correction to above

please read following occurrence

<input type="button" name="submit" class="button_light" value="Upload"

as

<input type="submit" name="submit" class="button_light" value="Upload"

thanks
This topic is locked and can not be replied to.