未捕获到的SyntaxError:意外令牌

时间:2019-11-27 18:26:19

标签: node.js

我目前收到此错误: Uncaught SyntaxError

,我不知道这是哪里来的。当我按编辑按钮时,会发生这种情况。这是我的代码:

我的article.html

<body>
  <h1 class = 'article-title'>Articles</h1>
  <h3 class = 'article-author'></h3>
  <p class = 'article-body'> </p>
  <button class = 'delete-button' value = 'delete'>DELETE</button>
  <button class = 'edit-button' value = 'edit'>EDIT</button>


</body>

我的article.js:

const editButton = document.querySelector('.edit-button');
    editButton.addEventListener('click', function(){
        console.log(url);
        api.editArticle(url, function(err,res){
            if (err) {
                console.log(err);
            }
        }) 
    })

我的api.js:

var api = (function(){
    "use strict";

    function send(method, url, data, callback){
        var xhr = new XMLHttpRequest();
        xhr.onload = function() {
            if (xhr.status !== 200) callback("[" + xhr.status + "] " + xhr.responseText, null);
            else callback(null, JSON.parse(xhr.responseText));
        }; 
        xhr.open(method, url, true);
        if (!data) xhr.send();
        else{
            xhr.setRequestHeader('Content-Type', 'application/json');
            xhr.send(JSON.stringify(data));
        }
    }

    var module = {};

    module.editArticle = function(url, callback){
        send("GET", '/edit_article' + url, null, callback)
    }
    return module;

})();

感谢您的帮助。

0 个答案:

没有答案