remotipart icon indicating copy to clipboard operation
remotipart copied to clipboard

Remotipart posting twice

Open lukasburns opened this issue 9 years ago • 6 comments

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

lukasburns avatar Jun 07 '15 07:06 lukasburns

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()

monttda avatar Jun 10 '15 22:06 monttda

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.

ThomasSertorio avatar Nov 09 '16 22:11 ThomasSertorio

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

Ammet avatar Apr 06 '17 14:04 Ammet

Is this still open issue, facing the same problem?

grsahil20 avatar Oct 29 '17 22:10 grsahil20

<%= 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.

capjuancode avatar Dec 13 '17 22:12 capjuancode

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).

togino77 avatar Jan 16 '18 04:01 togino77