【问题标题】:Rendering template via AJAX in Grails在 Grails 中通过 AJAX 渲染模板
【发布时间】:2012-01-11 05:03:36
【问题描述】:

我在一个动作中有以下代码

    render ( template: 'partial_list_template', model: [messageList: entries, totalFound: count, activeUILink: "all_mgs_link", termFreqs: null])

我在gsp页面中有如下代码

$j("#filterUpdate").click(function(event){

        var form = $j('#flags');



         new Ajax.Request('/tabulae/webForm/filter',
                {
                onSuccess:function(resp){

                               console.log(resp.responseText);
                                console.log($j('#filterResults'))
                                $j('#filterResults').remove()
                                $j('#filterResults').innerHTML(resp.responseText)
                            },
                            onError: function(resp) {
                                alert("Error:" + resp.toJSON());
                                return;
                            },
                            asynchronous:true,
                            evalScripts:true,
                            method:'GET',
                            parameters:form.serialize()

                });
      });

即使我在控制台日志中看到了 html 输出。我在添加此内容的元素中看不到 html 输出。任何想法为什么?

【问题讨论】:

    标签: jquery grails


    【解决方案1】:

    不要使用 .remove() ,因为那时您将删除该元素,并且在下一步中找不到任何元素。而且,没有称为 .innerHTML() 的方法 ...您应该使用 .html()

    希望有帮助

    【讨论】:

      【解决方案2】:

      尝试使用empty

      $j('#filterResults').empty();                            
        $j('#filterResults').innerHTML(resp.responseText);
      

      【讨论】:

      • 工作就像一个魅力。我之前尝试过empty和html,但由于某些原因,它不起作用。
      猜你喜欢
      • 2010-11-30
      • 1970-01-01
      • 2011-03-14
      • 1970-01-01
      • 2021-04-11
      • 2018-09-29
      • 1970-01-01
      • 2018-11-25
      • 1970-01-01
      相关资源
      最近更新 更多