简体   繁体   中英

$.ajax delete request not sending data parameters in capybara-webkit

I'm finding that my ajax DELETE requests are not sending data parameters to the controller when I execute them through capybara-webkit. However, the data parameters do get sent (and the test passes) when I run the test suite by using selenium. My code looks like the following:

$(document).on 'click', 'a.delete_contact', ->
  if confirm "Are you sure you want to delete this contact?"
    id = $('a.delete_contact').data('id')
    name = $('a.delete_contact').data('name')
    $.ajax '/contacts',
      type: 'DELETE'
      dataType: 'html'
      data: {'id' : id}
      success: ->
        $("li[data-cid='#{id}']").remove()
        removeInitial(_.last(name.split(" "))[0])
        show_notice("Contact successfully destroyed.", 'notice')
        window.contactSelection.pop()        
        refreshSelectionView()
  return false

Any ideas why this is failing in capybara-webkit?

Apparently QtWebKit does not support an entity body with DELETE requests.

https://github.com/thoughtbot/capybara-webkit/issues/427#issuecomment-12200262

A capybara-webkit developer recommended this work-around: "[Send] a POST request with a parameter identifying the request as a DELETE. This mechanism is used by Rails to work around similar issues across browsers."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM