Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remotipart posting twice #129

Open
lukasburns opened this issue Jun 7, 2015 · 6 comments
Open

Remotipart posting twice #129

lukasburns opened this issue Jun 7, 2015 · 6 comments

Comments

@lukasburns
Copy link

Hi, im using remotipart and paperclip for the file and it is posting twice and creating 2 objects, once with a html post and the second one with the JS post(the one I want). im using rails 4.2.1 and the lates version of remotipart.
Hope someone could help me
Thanx

@monttda
Copy link

monttda commented Jun 10, 2015

Same Issue with Rails '4.2.1' and remotipart 1.2.1. it does

Started POST "/operations/import" for 127.0.0.1 at 2015-06-10 18:03:50 -0430
Processing by OperationsController#import as /
Parameters: {"object Object"=>{","=>{"object Object"=>{","=>{"object Object"=>nil}}}}}

...

Started POST "/operations/import" for 127.0.0.1 at 2015-06-10 18:03:50 -0430
Processing by OperationsController#import as JS
Parameters: {"utf8"=>"✓", "commit"=>"Import", "remotipart_submitted"=>"true", "X-Requested-With"=>"IFrame", "X-Http-Accept"=>"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript, /; q=0.01", "file"=>#<ActionDispatch::Http::UploadedFile:0x007fa88d514428 @tempfile=#Tempfile:/tmp/RackMultipart20150610-5975-ldl9d9.csv, @original_filename="test.csv", @content_type="text/csv", @headers="Content-Disposition: form-data; name="file"; filename="test.csv"\r\nContent-Type: text/csv\r\n">}

...

This happens when uploading a file and using this form for doing so
(I'm using HAML so the reason for the syntax)

= form_tag import_operations_path,  remote: true, method: :post, multipart: true , id: "csv_document"do
    .row
      .col-xs-4
        = file_field_tag :file 
      .col-xs-4
        = submit_tag "Import", id: "send_csv"
      .col-xs-4 

Also one of the resquests has params without the uploaded file (the one as /) while the other has the file as You can see in the code up

As a solution to avoid this double call while the error persist I used the the next coffeescript which prevents the empty request(the one without the file ) to fire and only sends the one with the file

    $(document).ready ->
      $('#send_csv').on 'click', (e) ->
        e.preventDefault()
        $('#csv_document').submit()

@ThomasSertorio
Copy link

ThomasSertorio commented Nov 9, 2016

Same thing here with rails 5 and remotipart 1.3.1.
I've been checking other issues related to "double submit" but none of them help me to resolve the problem.

  • jquery_ujs is not double included
  • At each submit a second "empty" request is sent waiting for an HTML response
  • I also instantly get a Uncaught TypeError: $.rails.ajax(...).complete is not a functionfrom `jquery.remotipart``

Thanks @monttda for the temporary workaround.

@Ammet
Copy link

Ammet commented Apr 6, 2017

Catching Uncaught TypeError: $.rails.ajax(...).complete is not a function too..

@grsahil20
Copy link

Is this still open issue, facing the same problem?

@capjuancode
Copy link

<%= semantic_form_for([blah, blah], remote: true ) do |f| %>

  • The first Request is Controller#create as JS works but I have the same TypeError:
    Uncaught TypeError: $.rails.ajax(...).complete is not a function

  • Second Request Controller#create as HTML, because I don't have a handler for HTML 💥

is like jquery-ujs is not preventing its default functionality.

@togino77
Copy link

jqXHR.complete() callback was removed from jQuery 3.0.
Using jqXHR.always() instead of jqXHR.complete() gets rid of 'Uncaught TypeError: $.rails.ajax(...).complete is not a function' error. So 'ajax:beforeSend.remotipart' event function returns 'false' properly, browser never fire default submit event (second request as HTML).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants