我正在尝试将变量“response.data.uri”从我的 jQuery 获取到 rails 控制器,但它不起作用。我可以到达 rails 控制器,但变量不存在。
jQuery:
function responseCallbackHandler(response) {
switch (response.status) {
case 201:
$.ajax({ url: '#{addbank_bankaccts_path}',
type: 'POST',
beforeSend: function(xhr) {xhr.setRequestHeader('X-CSRF-Token', '#{form_authenticity_token}')},
dataType: "json",
data: 'account_uri=' + response.data.uri
success: function(response) {
// successfully executed the controller method
}
});
break;
}
}
路线.rb:
post "/bankaccts/new" => 'bankaccts#addbank'
控制器:
class BankacctsController < ApplicationController
def addbank
@uri = (params['customer_uri'])
@id = (params['id'])
@auri = (params['account_uri'])
# all equal nil ^
redirect_to root_url
end