Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/431.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 根据JS变量呈现Grails模板_Javascript_Jquery_Ajax_Grails - Fatal编程技术网

Javascript 根据JS变量呈现Grails模板

Javascript 根据JS变量呈现Grails模板,javascript,jquery,ajax,grails,Javascript,Jquery,Ajax,Grails,情况是:我有一个名为status的javascript bool变量。 如果这是真的,我想呈现一个Grails模板。 如果它为false,我想呈现另一个Grails模板。 我的代码: HTML/JS <div id="content"> <g:javascript> $( function(){ if( status==true ) { $.ajax({ url: '/tool/home/re

情况是:我有一个名为status的javascript bool变量。 如果这是真的,我想呈现一个Grails模板。 如果它为false,我想呈现另一个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>
我可以看到,这篇文章包含了正确的模板数据,但它没有被带到屏幕上


我这样做是否正确?

在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>
$.ajax({
url:“/tool/home/renderContent”,
键入:“POST”,
失败:函数(){alert(“加载内容帧失败”)},
成功:函数(response){$('#response').html(response);}
})
...

将成功处理程序添加到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>
$.ajax({
url:“/tool/home/renderContent”,
键入:“POST”,
失败:函数(){alert(“加载内容帧失败”)},
成功:函数(response){$('#response').html(response);}
})
...

我没有看到任何处理响应并将内容放入dom的代码。如何处理ajax响应?我没有看到任何处理响应并将内容放入dom的代码。如何处理ajax响应?