remotipart icon indicating copy to clipboard operation
remotipart copied to clipboard

ajax:success error? try this

Open ghost opened this issue 10 years ago • 5 comments

Add the :data => { :type => 'text' } to the form tag

:html => { :multipart => true, :data => { :type => 'text' } } }

works for you?

ghost avatar Jul 30 '14 00:07 ghost

Thanks! I was uploading files successfully, but my JS was nonetheless getting an ajax:error response. Adding :data => { :type => 'text' } to the form fixed it.

If it helps anyone, this is my controller code:

  def create
    @contact_document = ContactDocument.new(contact_document_params)

    if @contact_document.save
      render json: @contact_document
    else
      render json: { errors: @contact_document.errors.full_messages }, status: 422
    end
  end

A successful save was returning an ajax:error condition before I added :data => { :type => 'text' } to the form. After that, it started returning the ajax:success condition I was expecting.

toppa avatar Jan 16 '15 20:01 toppa

This same thing was happening for me. I tried type: :text and it was still a little off. Using type: :json worked for me!

tomprats avatar Mar 31 '15 21:03 tomprats

type: 'text' works for me (with an HTML response).

CodeMonkeySteve avatar Aug 22 '16 22:08 CodeMonkeySteve

This should probably be on the Readme.md

rapito avatar May 11 '18 09:05 rapito

I also had this problem and then found this issue. It would be good if this was on the README.

samstickland avatar Sep 23 '19 23:09 samstickland