在Rails中发送ajax请求时MultiJson :: DecodeError

odi*_*apc 4 ajax jquery ruby-on-rails

我有以下代码:

$.ajax({
  headers: {'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content'), 'Content-Type': 'application/json; charset=utf-8'},
  url:'/monitoring',
  type:'POST',
  data: {checked:{a:1}},
  dataType: 'json',
  success: function(){
  }
});
Run Code Online (Sandbox Code Playgroud)

发送此请求时抛出以下异常:

MultiJson :: DecodeError

"已检查%5Ba%5D = 1"意外令牌

这是什么?

odi*_*apc 6

我找到了解决方案.它现在有效(参见Content-Type):

$.ajax({
  headers: {'X-CSRF-Token': $('meta[name="csrf-token"]').attr('content'), 'Content-Type': 'application/x-www-form-urlencoded'},
  url:'/monitoring',
  type:'POST',
  data: {checked:{a:1}},
  dataType: 'json',
  success: function(){
  }
});
Run Code Online (Sandbox Code Playgroud)