1

我无法使用 AJAX 调用的 data 参数将变量传递给我的控制器。我究竟做错了什么?

显示.html.erb

var parentStepID = 20;

$.ajax({
    url: "/steps/create_branch",
    type: 'GET',
    data: {parent: parentStepID}
});

控制器

  def create_branch
    parentStepID = params[:parent]
    logger.debug("parentStepID: #{parentStepID}")
    respond_to do |format|
      format.js
    end
  end

记录器似乎没有得到 parentStepID:

Started GET "/projects/20/steps/create_branch" for 127.0.0.1 at 2013-03-06 11:56:44 -0500
Processing by StepsController#create_branch as HTML
  Parameters: {"project_id"=>"20"}
  Project Load (0.1ms)  SELECT "projects".* FROM "projects" WHERE "projects"."id" = ? LIMIT 1  [["id", "20"]]
####################################################################
parentStepID: 
  Rendered steps/create_branch.js.erb (0.1ms)
Completed 200 OK in 16ms (Views: 10.6ms | ActiveRecord: 0.1ms)

浏览器控制台:

20 0:412
/projects/20/steps/create_branch 0:413

另外,我相信 AJAX 请求工作正常;我在我的步骤视图文件夹中创建了一个名为“create_branch.js.erb”的文件,并放入了一个成功调用的警报。

4

0 回答 0