今天让我们看看怎样使用Rails和Ajax得到静态页面。
看下面这个页面:
[code]
<ul>
<li>
<div id="product-1" class="product-overview">
<span class="title">Learn to Program (Chris Pine)
<%= link_to_remote "detail",
:update => 'product-1-detail',
:method => 'get',
:url => '/catalog/details/1.html' %>
</span>
</div>
<div id='product-1-detail'></div>
</li>
</ul>
[/code]
这里link_to_remote生成一个detail链接,用户点击它时,就会取得1.html并替换id为product-1-detail的div的content。默认method为post,我们取静态内容所以改为get。
看下面这个页面:
[code]
<ul>
<li>
<div id="product-1" class="product-overview">
<span class="title">Learn to Program (Chris Pine)
<%= link_to_remote "detail",
:update => 'product-1-detail',
:method => 'get',
:url => '/catalog/details/1.html' %>
</span>
</div>
<div id='product-1-detail'></div>
</li>
</ul>
[/code]
这里link_to_remote生成一个detail链接,用户点击它时,就会取得1.html并替换id为product-1-detail的div的content。默认method为post,我们取静态内容所以改为get。