2014-09-22 87 views
0

我有我的控制器上的以下行動:JSON錯誤

def bank_response 
     @booking = Booking.where(order_number: params[:order]).first 
     if([email protected]_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 

感謝您的幫助

更新 - 鋼軌服務器


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
應用程序回溯------ -------完全回溯-------------- - multi_json(1.8.2)lib/multi_json/load_error.rb:6:在initialize' - multi_json (1.8.2) lib/multi_json.rb:122:in救援中負載' - multi_json (1.8.2)LIB/multi_json.rb:119:在load' - activesupport (3.2.13) lib/active_support/json/decoding.rb:15:in解碼 ' - ActionPack的(3.2.13) LIB/action_dispatch /中間件/ params_parser.rb:47:在 parse_formatted_parameters' - actionpack (3.2.13) lib/action_dispatch/middleware/params_parser.rb:17:in呼叫' - ActionPack的(3.2.13 )lib/action_dispatch/middleware/flash.rb:242: call' - rack (1.4.5) lib/rack/session/abstract/id.rb:210:in context' - rack(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:在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:在 __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:在 run_callbacks' - actionpack (3.2.13) lib/action_dispatch/middleware/callbacks.rb:27:in呼叫」 - ActionPack的 (3.2.13)LIB/action_dispatch /中間件/ reloader.rb:65:在call' - actionpack (3.2.13) lib/action_dispatch/middleware/remote_ip.rb:31:in 呼叫 ' - better_errors(1.0.1)LIB/better_errors/middleware.rb:84:在 protected_app_call' - better_errors (1.0.1) lib/better_errors/middleware.rb:79:in better_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:in call' - actionpack(3.2.13) lib/action_dispatch/middleware/show_exceptions.rb:56:in call' - railties (3.2.13) lib/rails/rack/logger.rb:32:in call_app' - r (3.2.13)lib/rails/rack/logger.rb:16:在call' - quiet_assets (1.0.2) lib/quiet_assets.rb:18:in call_with_quiet_assets' - actionpack(3.2.13)libr/rack/rack/logger.rb:16:block in call' - activesupport (3.2.13) lib/active_support/tagged_logging.rb:22:in 0.13) LIB/action_dispatch /中間件/ request_id.rb:22:在call' - rack (1.4.5) lib/rack/methodoverride.rb:21:in呼叫 ' - 齒條(1.4.5) LIB /齒條/ runtime.rb:17:在call' - activesupport (3.2.13) lib/active_support/cache/strategy/local_cache.rb:72:in呼叫' - 齒條 (1.4.5) lib/rack/lock.rb:15:在call' - actionpack (3.2.13) lib/action_dispatch/middleware/static.rb:63:in調用' - railties (3.2.13)lib/rails/engine.rb:479:在call' - railties (3.2.13) lib/rails/application.rb:223:in調用' - rack(1.4.5) lib/rack/content_length。 rb:14:在call' - railties (3.2.13) lib/rails/rack/log_tailer.rb:17:in中調用' - thin(1.5.1) lib/thin/connection.rb:81:in block in pre_process' - thin (1.5.1) lib/thin/connection.rb:79:in pre_process' - thin(1.5.1) lib/thin/connection。rb:54:in process' - thin (1.5.1) lib/thin/connection.rb:39:in receive_data' - eventmachine(1.0.3) lib/eventmachine.rb:187:in run' - thin (1.5.1) lib/thin/backends/base.rb:63:in start' - thin(1.5.1) lib/thin/server.rb:159:in start' - rack (1.4.5) lib/rack/handler/thin.rb:13:in run' - rack(1.4.5) lib/rack/server.rb:268:in start' - railties (3.2.13) lib/rails/commands/server.rb:70:in start' - railties(3.2.13) lib/rails/commands.rb:55:in block in <top (required)>' - railties (3.2.13) lib/rails/commands.rb:50:in' - script/rails:6 :在<main>' - script/rails:0:in'

UPDATE解決


球員,米y的問題是類型:「POST」,因爲我正在做一個「GET」

無論如何感謝。

+0

任何錯誤消息在控制檯上? – worldask 2014-09-22 14:41:48

+0

@worldask只有郵政http:// localhost:3000/bank_response/ffgs1d79aatc 500(內部服務器錯誤) – Jean 2014-09-22 14:44:40

+0

看看你的導航服務器屏幕 – worldask 2014-09-22 14:48:51

回答

0

與您迴應就必須做somethiing liek此:

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

謝謝你,但我想我有另一個錯誤,因爲如果我去我的http:// 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」等等等等等等)我想我正在發送正確的信息,但是我的問題是當我嘗試使用ajax做同樣的事情時 – Jean 2014-09-22 14:46:06