无法使AJAX和JQuery在rails中工作
我正在从事一个Rails项目,并尝试使用$.post从服务器获取一些数据,但什么也没有发生。有人知道出了什么问题吗 HTML文件无法使AJAX和JQuery在rails中工作,jquery,ruby-on-rails,ajax,coffeescript,Jquery,Ruby On Rails,Ajax,Coffeescript,我正在从事一个Rails项目,并尝试使用$.post从服务器获取一些数据,但什么也没有发生。有人知道出了什么问题吗 HTML文件 <a id="ta" role="button" class="btn">tzt</a> <div id="ggg">Code goes here</div> routes.rb match '/hype', to: 'items#xxx' controller.rb def xxx @item = Item.
<a id="ta" role="button" class="btn">tzt</a>
<div id="ggg">Code goes here</div>
routes.rb
match '/hype', to: 'items#xxx'
controller.rb
def xxx
@item = Item.last
return render :text => "New Text"
end
def xxx
@item = Item.last
render :text => "New Text"
end
js文件应该是这样的
$ ->
$('#ta').click (e) ->
e.preventDefault()
$.post "/hype", (data) ->
$("#ggg").html data
需要在post后调用函数,请尝试:
.js文件
controller.rb
def xxx
@item = Item.last
return render :text => "New Text"
end
def xxx
@item = Item.last
render :text => "New Text"
end
要确保url正常,只需在浏览器地址栏中测试它什么叫“无”?是否未触发单击事件?单击事件是否未发布?数据是否未返回?使用Firebug来关注浏览器中发生的事情,这样你就可以了解答案了代码中缩进了:)我在这里写问题的时候出了点问题。