【问题标题】:json error on ruby on railsruby on rails上的json错误
【发布时间】:2014-11-16 13:49:37
【问题描述】:

我的控制器上有以下操作:

def bank_response
        @booking = Booking.where(order_number: params[:order]).first
        if(!@booking.Ds_Response.nil?)
            respond_to do |format|
            format.json {  render json: @booking, success: 200  }
          end
        end
    end

在我的 Newview 上,我有以下代码:

setInterval(function(){
      $.ajax({
        url: "/bank_response/#{@order_number}",
        type: "POST",
        contentType: 'application/json; charset=UTF-8',
        data: {"order" : "#{@order_number}"},
        dataType: "json",
        success: function(result){
          alert("success");
        },
        error: function(result) {
          alert("error");
        }
      });
    },10000);

我也有一个这样的 bank_response 视图:

{  "booking" : "#{@booking.to_s}" }

但我总是从我的新视图中收到错误 500。

Remote Address:127.0.0.1:3000
Request URL:http://localhost:3000/bank_response/609nrhqlewbi
Request Method:POST
Status Code:500 Internal Server Error
Request Headersview source

感谢您的帮助

更新 - RAILS 服务器


MultiJson::LoadError 在 /bank_response/ffgs1d79aatc============================================== =====> 795:'order=ffgs1d79aatc'multi_json (1.8.2) 处的意外令牌 lib/multi_json/load_error.rb,行 6------------------------------------------------ ------ruby 1 module MultiJson 2 class LoadError < StandardError 3
attr_reader :data 4 def initialize(message='', backtrace=[], data='') 5 super(message)> 6
self.set_backtrace(backtrace) 7 @data = data 8 end 9 end 10 DecodeError = LoadError # Legacy support 11
end
App回溯-------------完整回溯-------------- multi_json (1.8.2) lib/multi_json/load_error.rb:6:in initialize' - multi_json (1.8.2) lib/multi_json.rb:122:inrescue in load' - multi_json (1.8.2) lib/multi_json.rb:119:in load' - activesupport (3.2.13) lib/active_support/json/decoding.rb:15:indecode' - 动作包 (3.2.13) lib/action_dispatch/middleware/params_parser.rb:47:in parse_formatted_parameters' - actionpack (3.2.13) lib/action_dispatch/middleware/params_parser.rb:17:incall' - actionpack (3.2.13) lib/action_dispatch/middleware/flash.rb:242:in call' - rack (1.4.5) lib/rack/session/abstract/id.rb:210:incontext' - 机架 (1.4.5) lib/rack/session/abstract/id.rb:205:in call' - actionpack (3.2.13) lib/action_dispatch/middleware/cookies.rb:341:in call' - actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:28:in block in call' - activesupport (3.2.13) lib/active_support/callbacks.rb:405:in _run__4308745349437725987__call__4526229337647608189__callbacks' - activesupport (3.2.13) lib/active_support/callbacks.rb:405:in __run_callback' - activesupport (3.2.13) lib/active_support/callbacks.rb:385:in_run_call_callbacks' - activesupport (3.2.13) lib/active_support/callbacks.rb:81:in run_callbacks' - actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:27:incall' - 动作包 (3.2.13) lib/action_dispatch/middleware/reloader.rb:65:in call' - actionpack (3.2.13) lib/action_dispatch/middleware/remote_ip.rb:31:in call'-better_errors (1.0.1) lib/better_errors/middleware.rb:84:in protected_app_call' - better_errors (1.0.1) lib/better_errors/middleware.rb:79:inbetter_errors_call' - better_errors (1.0.1) lib/better_errors/middleware.rb:56:in call' - actionpack (3.2.13) lib/action_dispatch/middleware/debug_exceptions.rb:16:incall' - 动作包 (3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in call' - railties (3.2.13) lib/rails/rack/logger.rb:32:incall_app' - railties (3.2.13) lib/rails/rack/logger.rb:16:in block in call' - activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in tagged' - railties (3.2.13) lib/rails/rack/logger.rb:16:in call' - quiet_assets (1.0.2) lib/quiet_assets.rb:18:in call_with_quiet_assets' - actionpack (3.2.13) lib/action_dispatch/middleware/request_id.rb:22:in call' - rack (1.4.5) lib/rack/methodoverride.rb:21:incall' - 机架 (1.4.5) lib/rack/runtime.rb:17:in call' - activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:incall' - 机架 (1.4.5) lib/rack/lock.rb:15:in call' - actionpack (3.2.13) lib/action_dispatch/middleware/static.rb:63:incall' - railties (3.2.13) lib/rails/engine.rb:479:in call' - railties (3.2.13) lib/rails/application.rb:223:incall' - 机架 (1.4.5) lib/rack/content_length.rb:14:in call' - railties (3.2.13) lib/rails/rack/log_tailer.rb:17:incall' - 瘦 (1.5.1) lib/thin/connection.rb:81:in block in pre_process' - thin (1.5.1) lib/thin/connection.rb:79:inpre_process' - 瘦 (1.5.1) lib/thin/connection.rb:54:in process' - thin (1.5.1) lib/thin/connection.rb:39:inreceive_data' - eventmachine (1.0.3) lib/eventmachine.rb:187:in run' - thin (1.5.1) lib/thin/backends/base.rb:63:instart' - 瘦 (1.5.1) lib/thin/server.rb:159:in start' - rack (1.4.5) lib/rack/handler/thin.rb:13:inrun' - 机架 (1.4.5) lib/rack/server.rb:268:in start' - railties (3.2.13) lib/rails/commands/server.rb:70:instart' - railties (3.2.13) lib/rails/commands.rb:55:in block in <top (required)>' - railties (3.2.13) lib/rails/commands.rb:50:in' - 脚本/rails:6:in &lt;main&gt;' - script/rails:0:in'

更新已解决


伙计们,我的问题是类型:“POST”,因为我正在制作“GET”

还是谢谢。

【问题讨论】:

  • 您的控制台上有任何错误消息吗?
  • @worldask only POST localhost:3000/bank_response/ffgs1d79aatc 500(内部服务器错误)
  • 查看您的 Rails 服务器屏幕
  • @worldask 我刚刚发布了 Rails 服务器屏幕

标签: ruby-on-rails ruby json haml


【解决方案1】:

要回复你,你必须做一些事情,比如:

format.json do
    render json: {
      booking_attr: @booking.attr,
      booking_second_attr: @booking_second_attr,
      id: @booking.id
    }
  end
end

【讨论】:

  • 谢谢 jose,但我想我还有另一个错误,因为如果我转到我的 localhost:3000/bank_response/ORDERNUMBER.json,我会得到以下 {"Ds_Amount":"2500","Ds_AuthorisationCode":"508380"," Ds_Card_Country":"724","Ds_Card_Type":null,"Ds_ConsumerLanguage":"1","Ds_Currency":"978","Ds_Date":"22/09/2014","Ds_Hour":"13:37" , etc etc etc} 所以我认为我正在发送正确的信息,但我的问题是当我尝试使用 ajax 做同样的事情时
猜你喜欢
  • 2015-11-27
  • 2018-03-08
  • 1970-01-01
  • 2013-03-21
  • 1970-01-01
  • 2017-06-15
  • 2014-04-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多