我通过 jQuery AJAX 将信息发送到 post 方法。然后我想重定向到我的主页。但redirect_to root_url
在这种情况下不起作用。从ajax帖子重定向的正确方法是什么?
jQuery:
function responseCallbackHandler(response) {
switch (response.status) {
case 400:
console.log(response.error);
break;
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
});
break;
}
}
控制器:
class BankacctsController < ApplicationController
def addbank
# some logic here
redirect_to root_url, :notice => "Back account added!"
end
end