ruby-on-rails - 对 Rails 的 AJAX 请求省略了右花括号
问题描述
我在这个 repo上找到了一个托管在 heroku 上的应用程序(提供完整源代码)。
当我执行 post 或 put 请求时,缺少右花括号。例如,此处找到的代码执行发布以创建食谱。
this.axios.post('recipes', { recipe: resource });
我在网络工具中看到以下原始请求。
{"recipe":{"ingredients":"","name":"t","tags":[],"categories":[]}}
但是服务器端我看到了这个错误。
{"recipe":{"ingredients":"","name":"test","tags":[],"categories":[]
ActionDispatch::Http::Parameters::ParseError (765: unexpected token at '{"recipe":{"ingredients":"","name":"test","tags":[],"categories":[]'):
rails/actionpack/lib/action_dispatch/http/parameters.rb:117: in `rescue in parse_formatted_parameters'
rails/actionpack/lib/action_dispatch/http/parameters.rb:111:in `parse_formatted_parameters'
rails/actionpack/lib/action_dispatch/http/request.rb:381:in `block in POST'
就好像最后两个花括号被切断了一样。我一路跳进去ActionDispatch::Request
撬
> get_header "RAW_POST_DATA"
=> "\r\n" + "{\"recipe\":{\"ingredients\":\"\",\"name\":\"t\",\"tags\":[],\"categories\":[]"
我不知道它是来自 axios 侧还是 rails 侧。由于开发工具显示了一个有效的请求,我假设它在 Rails 一侧,但我不知道是什么原因造成的。
它适用于heroku,但不适用于开发环境,我想不出有什么改变。要重现,您可以像任何其他 Rails 应用程序一样设置并为用户播种并尝试创建带有标题的食谱。
解决方案
推荐阅读
- javascript - 使用 mongoose 一次将多个 ObjectId 插入子文档
- c++ - 如何在 SFML 2.5 中调整窗口大小时保持窗口纵横比?
- javascript - NodeJS:需要帮助来构建带有括号和大括号的对象
- sorting - ansible中2个列表的所有组合
- python - 在另一个 QWidget 类的函数中启动自定义 QWidget
- c# - ASP.NET Core 中的 net::ERR_CERT_AUTHORITY_INVALID
- python - 如何通过请求从django模板中的列表中检索数据
- mysql - 使用 show create 功能失去与服务器的连接
- regex - 将文件内容与模式/正则表达式匹配(编辑后重新发布)
- javascript - 使用 puppeteer 按文本选择