Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6212339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:29:51+00:00 2026-05-24T06:29:51+00:00

I’m creating a new blog form and I have a few photo upload fields

  • 0

I’m creating a “new blog” form and I have a few photo upload fields in the form. Is there a way I can send the post request using AJAX, uploading the photo, and return the photos url to display on the “new blog” form? My back end is written in ruby on rails.

I hope that makes sense! Any help greatly appreciated it!

Thanks,
Alex

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:29:53+00:00Added an answer on May 24, 2026 at 6:29 am

    Yes, but it’s a little complicated. The problem is that you cannot send uploaded files via AJAX, BUT there is a straightforward workaround which most people use.

    This is how it works: You upload the photo into an invisible iFrame. You set this iframe as the upload form’s target, and the user will be able to submit the form without reloading the page.

    Example:

    <iframe id="upload"></iframe>
    <%= form_for @photo, :html => { :multipart => true, :id => 'photo_upload_form', :target => 'upload' }, :url => photos_path do |f| %>
      <div class="field">
        <%= f.label :image, 'Upload Photo' %>
        <%= f.file_field :image %>
      </div>    
    <% end %>
    

    …and of course use CSS to hide the iFrame. I think I once had an issue with hiding the iFrame with display: none, so I would recommend moving it off-screen by using something like:

    #upload { position: absolute; left: -10px; top: -10px; width: 1px; height: 1px; }
    

    Finally, you can use JavaScript in the view which is rendered inside the hidden iFrame via window.parent, so this way you can actually display the uploaded image inside the upload form.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I am using Paperclip to handle profile photo uploads in my app. They upload
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a small JavaScript validation script that validates inputs based on Regex. I
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.