以下 JavaScript 向我的 rails 服务器发送一个XMLHttpRequest
带有参数的参数recipe_num
,我如何从控制器中提取数据?我试过params[:recipe_num]
和session[:recipe_num]
,两者都不起作用。
function getRules(recipe_num){
var request = new XMLHttpRequest;
request.open("POST", "/path/rules_json?format=json", true);
var token = $("meta[name='csrf-token']").attr("content");
request.setRequestHeader("X-CSRF-Token", token);
request.onreadystatechange = function() {
if(request.readyState == request.DONE){
buildForm(JSON.parse(request.responseText));
}
};
request.send("recipe_num=" + recipe_num);
};