[英]Uncaught SyntaxError Unexpected Identifier
I get this error: Uncaught SyntaxError Unexpected Identifier我收到此错误:Uncaught SyntaxError Unexpected Identifier
{% extends 'tweets/base.html' %}
{% block content %}
Welcome to TweetMe
<div id='tweets'></div>
<script>
const tweetsElement = document.getElementById('tweets')
tweetsElement.innerHTML = 'loading...'
const xhr = new XMLHttpRequest()
const method = 'GET'
const url = 'tweets/'
const responseType = "json"
function likeBtn() {
return '<button class='btn btn-primary'>Like</button>'
}
function formatTweetElement(tweet) {
console.log('HELLO');
var formattedTweet = `
<div class="mb-4" id="tweet-id-${tweet.id}">
<p>${tweet.user}</p>
<p>${tweet.content}</p>
${likeBtn()}
</div>`;
console.log(formattedTweet)
return formattedTweet
}
xhr.responseType = responseType
xhr.open(method, url)
xhr.onload = function() {
const serverResponse = xhr.response
var listedItems = serverResponse.response
console.log(listedItems)
var finalTweetStr = ""
for (i in listedItems) {
var tweetObj = listedItems[i]
finalTweetStr += formatTweetElement(tweetObj)
}
tweetsElement.innerHTML = finalTweetStr
}
xhr.send()
</script>
{% endblock content %}
Please ignore the {% block content %}
parts, it's valid when rendering in Django.请忽略
{% block content %}
部分,在 Django 中渲染时有效。 Can anyone help me with my error?谁能帮我解决我的错误? All I know is that there is something wrong in the
<script></script>
section.我只知道
<script></script>
部分有问题。
Problem is in问题在
function likeBtn() {
return '<button class='btn btn-primary'>Like</button>'
}
you use the same kind of quotes.您使用相同类型的引号。
Use利用
function likeBtn() {
return '<button class="btn btn-primary">Like</button>'
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.