我发现当我通过 capybara-webkit 执行它们时,我的 ajax DELETE 请求没有向 Controller 发送数据参数。但是,当我使用 selenium 运行测试套件时,确实会发送数据参数(并且测试通过)。我的代码如下所示:
$(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
知道为什么这在 capybara-webkit 中失败了吗?
最佳答案
显然 QtWebKit 不支持带有 DELETE 请求的实体主体。
https://github.com/thoughtbot/capybara-webkit/issues/427#issuecomment-12200262
capybara-webkit 开发人员推荐了这种变通方法:“[发送] 一个 POST 请求,其中包含一个将请求标识为 DELETE 的参数。Rails 使用这种机制来解决跨浏览器的类似问题。”
关于javascript - $.ajax 删除请求不在 capybara-webkit 中发送数据参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16044184/