0

我想在 jQuery 中使用定期更新程序来定期更新聊天 div。因此,我在布局文件中包含 jQuery 库:

<g:javascript library="jquery" plugin="jquery"/>

从页面http://www.360innovate.co.uk/blog/2009/03/periodicalupdater-for-jquery/我下载了 jquery 的 periodicalupdater 插件并将其链接到我的 gsp 页面:

<g:javascript src="jquery.periodicalupdater.js"/>

在我的页面上,我使用这个脚本来启动 periodicalUpdater:

<script type="text/javascript">
    $(document).ready(function() {
        $.PeriodicalUpdater({
            url : 'URL'
        }, function(data) {
            var myHtml = 'The data returned from the server was: ' + data + '';
        });
    });
</script>

问题是,甚至没有调用 URL。查看浏览器控制台时出现以下错误:

'undefined' is not a function (evaluating '$.PeriodicalUpdater')

编辑:我解决了这个问题。periodUpdater 插件刚刚在 jquery 之前加载。但现在我有另一个问题。我在我的代码中写了以下几行:

<g:javascript library="jquery" /><script type="text/javascript">
    $(document).ready(function() {
        $.PeriodicalUpdater({url : 'http://localhost:8080/PROJECT/comment/ajax_list/1'},
        function(data){$('#comment').empty().append(data);});
    });
</script>

我想要没有本地主机的 URL,因为我也想在生产模式下加载它......

4

1 回答 1

2

In my layout file I have the following:

<script>
    contextPath = "${request.contextPath}";
</script>

And then updating your code:

<script type="text/javascript">
    $(document).ready(function() {
        $.PeriodicalUpdater({url : contextPath + '/comment/ajax_list/1'},
        function(data){$('#comment').empty().append(data);});
    });
</script>
于 2012-10-23T15:20:53.757 回答