Javascript 请求使用撇号’;s服务器

Javascript 请求使用撇号’;s服务器,javascript,request,apostrophe-cms,Javascript,Request,Apostrophe Cms,我想在我的j=Javascript代码中向撇号的服务器发出请求(比如PUT、POST…)。我这样做了,但不起作用: {% extends "layout.html" %} {% block main %} <div class="main-content"> <h3>Hello world! {% if not data.user %} <a class="login-link" href="/login">L

我想在我的j=Javascript代码中向撇号的服务器发出请求(比如PUT、POST…)。我这样做了,但不起作用:

{% extends "layout.html" %}

{% block main %}
    <div class="main-content">
    <h3>Hello world!
        {% if not data.user %}
        <a class="login-link" href="/login">Login</a>
        {% endif %}
    </h3>
    <p>This is a very bare bones Apostrophe project. Now, get to work and make a real website!</p>
    </div>
    {{
        apos.area(data.page, 'body', {
        widgets: {
            'apostrophe-images': {
                size: 'full'
            },
            'apostrophe-rich-text': {
                toolbar: [ 'Styles', 'Bold', 'Italic', 'Link', 'Unlink' ],
                styles: [
                    { name: 'Heading', element: 'h3' },
                    { name: 'Subheading', element: 'h4' },
                    { name: 'Paragraph', element: 'p' }
                ]
            }
        }
    })

    self.apos.tasks.add(self.__meta.name, 'insert-stuff', function(apos, argv, callback) {
        var req = self.apos.tasks.getReq();
        return self.find(req, { cool: true }).toArray().then(function(err, pieces) {
            if (err) {
                return callback(err);
            }
        });
    };

}}
{% endblock %}

你仔细检查语法了吗?你是否在self.apos.tasks.add的末尾缺少一个
?你试图在Nunjucks模板文件中编写JavaScript。另外,您开始使用的代码示例是命令行任务,而不是快速路线。这里没有任何前端JavaScript尝试与该路由通信(如果存在的话)。我将在撇号示例repo中准备一个示例,演示如何从浏览器中创建路由并与其通信。本教程确实演示了如何创建路由并正确地与它们通信,但仅使用该功能的简单示例就可以了:
e.stack: Template render error: (apostrophe-pages:pages/home.html) [Line 34, Column 3]
expected variable end
at Object.exports.prettifyError (C:\Windows\System32\test-project\node_modules\nunjucks\src\lib.js:34:15)
at new_cls.render (C:\Windows\System32\test-project\node_modules\nunjucks\src\environment.js:469:27)
at Object.self.renderBody (C:\Windows\System32\test-project\node_modules\apostrophe\lib\modules\apostrophe-templates\index.js:309:47)
at Object.self.renderForModule (C:\Windows\System32\test-project\node_modules\apostrophe\lib\modules\apostrophe-templates\index.js:176:19)
at Object.self.render (C:\Windows\System32\test-project\node_modules\apostrophe\lib\modules\apostrophe-module\index.js:173:34)
at Object.self.renderPageForModule (C:\Windows\System32\test-project\node_modules\apostrophe\lib\modules\apostrophe-templates\index.js:666:28)
at C:\Windows\System32\test-project\node_modules\apostrophe\lib\modules\apostrophe-module\index.js:349:31
at C:\Windows\System32\test-project\node_modules\async\lib\async.js:726:13
at C:\Windows\System32\test-project\node_modules\async\lib\async.js:52:16
at C:\Windows\System32\test-project\node_modules\async\lib\async.js:269:32
at C:\Windows\System32\test-project\node_modules\async\lib\async.js:44:16
at C:\Windows\System32\test-project\node_modules\async\lib\async.js:723:17
at C:\Windows\System32\test-project\node_modules\async\lib\async.js:167:37
at C:\Windows\System32\test-project\node_modules\async\lib\async.js:52:16
at iterate (C:\Windows\System32\test-project\node_modules\async\lib\async.js:260:24)
at Object.async.forEachOfSeries.async.eachOfSeries (C:\Windows\System32\test-project\node_modules\async\lib\async.js:281:9)
:: 2018-08-17T10:43:23+0200: template error at /
Current user: admin
{ Template render error: (apostrophe-pages:pages/home.html) [Line 34, Column 3]
expected variable end
at Object.exports.prettifyError (C:\Windows\System32\test-project\node_modules\nunjucks\src\lib.js:34:15)
at new_cls.render (C:\Windows\System32\test-project\node_modules\nunjucks\src\environment.js:469:27)
at Object.self.renderBody (C:\Windows\System32\test-project\node_modules\apostrophe\lib\modules\apostrophe-templates\index.js:309:47)
at Object.self.renderForModule (C:\Windows\System32\test-project\node_modules\apostrophe\lib\modules\apostrophe-templates\index.js:176:19)
at Object.self.render (C:\Windows\System32\test-project\node_modules\apostrophe\lib\modules\apostrophe-module\index.js:173:34)
at Object.self.renderPageForModule (C:\Windows\System32\test-project\node_modules\apostrophe\lib\modules\apostrophe-templates\index.js:666:28)
at C:\Windows\System32\test-project\node_modules\apostrophe\lib\modules\apostrophe-module\index.js:349:31
at C:\Windows\System32\test-project\node_modules\async\lib\async.js:726:13
at C:\Windows\System32\test-project\node_modules\async\lib\async.js:52:16
at C:\Windows\System32\test-project\node_modules\async\lib\async.js:269:32
at C:\Windows\System32\test-project\node_modules\async\lib\async.js:44:16
at C:\Windows\System32\test-project\node_modules\async\lib\async.js:723:17
at C:\Windows\System32\test-project\node_modules\async\lib\async.js:167:37
at C:\Windows\System32\test-project\node_modules\async\lib\async.js:52:16
at iterate (C:\Windows\System32\test-project\node_modules\async\lib\async.js:260:24)
at Object.async.forEachOfSeries.async.eachOfSeries (C:\Windows\System32\test-project\node_modules\async\lib\async.js:281:9) name: ‘Template render error’ }