我正在尝试通过AJAX提交提取数据并将其呈现为主干中的div #search_results
。我该怎么做呢?我是骨干的新手,还在学习。
谢谢!
RoR控制器:
class ClassroomsController < PublicController
def search
@search_result = Classroom.first
respond_with @search_result
end
end
RoR查看:
= form_tag search_path, :method => :get, :id => "search_form", do
= text_field_tag :search_textbox
= submit_tag "Search", :id => "search_button"
#search_results
教室/ search.js.erb:
$("#search_results").html("<%=escape_javascript(render 'search')%>");
教室/ search.html.haml:
= @search_result.classroom.title
backbone.js查看:
class Classrooms.Views.Classroom extends Backbone.View
events:
"submit #search_button": "getResults"
render: ->
$(@el).html($("#classroom_main").html())
@setActiveNavItem("main")
this
getResults: (event) ->
event.stopPropagation()
event.preventDefault()
$.get $(this).attr("action"), $(this).serialize(), null, "script"
return false
答案 0 :(得分:0)
你好BackboneJS工作不同, 它在客户端有一个MVC和一个RESTful后端。
http://www.quora.com/How-can-I-use-Backbone-js-with-Ajax-calls-to-the-server/answer/Diego-Castorina
也许这个链接可以帮助你理解MVC,REST和Backbone:
祝你好运