gpt4 book ai didi

javascript - 谷歌搜索控制台错误: Uncaught SyntaxError: Unexpected token function

转载 作者:行者123 更新时间:2023-12-03 00:19:03 26 4
gpt4 key购买 nike

我这里有语法错误吗?

<script type="text/javascript">
async function showWidget(physicianId, locationId, format)
{
var response = await fetch('https://reviews.rater8.com/webwidget/api/ratingsummary/' + physicianId + '?format=' + format);
var snippet = await response.text();
document.getElementById(locationId).innerHTML = snippet;
}
</script>

此功能有效,您可以在以下位置看到该页面:

https://reviews.rater8.com/webwidget/sample.html

但是,Google 看不到我通过该函数动态插入页面的内容。我使用 Google Search Console 来查看原因,并发现 Google 正在标记该页面有两个错误:

  1. 未捕获的语法错误:意外的标记函数 https://reviews.rater8.com/webwidget/sample.html:12

(即关键字“async”后面的关键字“function”。)

  • Uncaught ReferenceError :showWidget 未定义 https://reviews.rater8.com/webwidget/sample.html:20
  • 当然,如果函数定义无法解析,则不会定义该函数。我可以通过删除关键字 async 来消除解析错误,但函数无法正确执行!

    最佳答案

    以下是如何在不使用 JavaScript 等待机制的情况下完成工作。

    <script type="text/javascript">
    function showWidget(physicianId, locationId, format)
    {
    fetch('https://reviews.rater8.com/webwidget/api/ratingsummary/' + physicianId + '?format=' + format)
    .then(function (response) {
    response.text()
    .then(function (snippet) {
    document.getElementById(locationId).innerHTML = snippet;
    })
    })
    }
    </script>

    Google 能够查看通过此方法生成的内容。

    关于javascript - 谷歌搜索控制台错误: Uncaught SyntaxError: Unexpected token function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54408012/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com