我的javascript中有一个方法,可以将表单形式的ajax的数据发送到我的ruby控制器中的操作
$scope.pay_spei = function () {
$('#pay_spei').attr("disabled", true);
var concepts = JSON.stringify($scope.transaction_spei.getConcepts());
$.ajax({
url: '/payment_spei/charge',
type: "POST",
data: {
payment_spei: concepts
},
success: function (data) {
console.log("SUCCESS!");
},
error: function (data) {
console.log("ERROR");
}
}).success(function () {
window.location.href = "/payment_spei/charge";
});
};
在我的控制台中:
Processing by PaymentSpeiController#charge as */*
Parameters: {"payment_spei"=>"[{\"name\":\"bbbbb\",\"quantity\":12,\"unit_price\":10000,\"$$hashKey\":\"object:3\"}]"}
{"payment_spei"=>"[{\"name\":\"bbbbb\",\"quantity\":12,\"unit_price\":10000,\"$$hashKey\":\"object:3\"}]", "controller"=>"payment_spei", "action"=>"charge"}
在我的控方的行动中,这些数据消失了:
def charge
concepts = JSON.parse(params[:payment_spei])
end
向我抛出此错误
PaymentSpeiController#charge中的TypeError 没有将nil隐式转换为String
当我在javascript中删除重定向时,不会出现此错误
window.location.href = "/payment_spei/charge"
我需要从页面重定向,如何解决此错误?