hol*_*ich 1 javascript ajax jquery grails
情况是:我有一个名为 status 的 javascript bool 变量。如果是真的,我想渲染一个 Grails 模板。如果它是假的,我想呈现另一个 Grails 模板。我的代码:
HTML/JS
<div id="content">
<g:javascript>
$( function(){
if( status==true ) {
$.ajax({
url: '/tool/home/renderSplash',
type: 'POST',
failure: function(){alert("Failed loading content frame"})
}
else{
$.ajax({
url: '/tool/home/renderContent',
type: 'POST',
failure: function(){alert("Failed loading content frame")}
})
}
} )
</g:javascript>
</div>
Run Code Online (Sandbox Code Playgroud)
圣杯:
class HomeController {
def index() {}
def renderSplash() {
render( template: "splash" )
}
def renderContent() {
render( template: "content" )
}
}
Run Code Online (Sandbox Code Playgroud)
我可以看到,POST 包含正确的模板数据,但没有显示在屏幕上。
我这样做是否正确?
向呈现结果的 AJAX 调用添加一个成功处理程序。您需要一个占位符元素来呈现它。例子:
$.ajax({
url: '/tool/home/renderContent',
type: 'POST',
failure: function(){alert("Failed loading content frame")},
success: function(response) { $('#response').html(response); }
})
...
<div id='response'></div>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2119 次 |
| 最近记录: |