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

走远了吗. 提交于 2020-01-02 05:46:13

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/16044184/ajax-delete-request-not-sending-data-parameters-in-capybara-webkit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!